1,032 questions
1
vote
1
answer
67
views
Raman spectral data format for MCR-ALS [closed]
I have a chemometrics project where I need to put Raman Spectroscopy data files into a Multivariate Curve Resolution model. I have been given .CNF files which came off the instrument, converted into ....
2
votes
1
answer
94
views
implicit function fit, linear regression with x and y std
In order to solve a weigthed linear regression (with x and y weights), I converted the explicit to implicit expression.
We are given (xmean,xstd) , (ymean,ystd) each 1d of length n.
The error is given ...
0
votes
1
answer
46
views
How to perform pairwise weighted least squares regression on multiple columns?
I'm working with DolphinDB and trying to compute weighted least squares (WLS) regression between multiple pairs of columns in a table. The mslr function (moving least squares regression) works ...
0
votes
0
answers
19
views
In DolphinDB, how to calculate stock residual return based on a table using the ols function?
I have a table “clean_factor“ where the column “y“ indicates the stock returns and the subsequent columns indicate factor exposures. How do I calculate the daily residual return of each stock with the ...
0
votes
0
answers
31
views
Absolute Value bounds for lmfit? Trying to use lmfit to non-linear least squares fit for a function with an undefined region between -0.1 and 0.1
I'm trying to fit data to a bidirectional exponential gaussian function (equation below) using lmfit. The equation has four variables: center, amplitude, sigma, and gamma. The first three are always ...
0
votes
0
answers
66
views
Least-Squares Monte Carlo implementation
I am implementing the least squares monte carlo method to price american put (and maybe call) options in the 4/2 stochastic volatility process. For this I generate paths first and then I want to use ...
2
votes
0
answers
49
views
how to specify that the error term is an AR(1) process using IV2SLS regression of Python statsmodel?
I am trying to replicate an eviews code in Python. I need to fit a regression with a constant, some endogeneous variables that I instrumentalize and some exogeneous variables. The dependant variable ...
3
votes
1
answer
159
views
Numpy/scipy - How to find the least squares solution with the constraint that Ax >= b?
I have a linear algebra problem that I can't find the correct function for; I need to find the vector x that satisfies Ax = b. Because A is non-square (there's 5 columns and something like 37 rows), ...
0
votes
1
answer
46
views
Allow x to shift during linear combination fitting
I have three sets of data (x,y) that define unique lineshapes. Using linear combination fitting I want to fit these three lineshapes to a fourth. I can set up the simple code below:
#read in data (...
0
votes
1
answer
111
views
Correct calculation of r square (R^2) using visual basic WorksheetFunction.LinEst function
I have written visual basic code to determine the r square when fitting data using different order polynomials:
Linear
2nd order polynomial
3rd order polynomial
As an example, I have used the ...
0
votes
1
answer
64
views
Implementation of the parameters error in the Matlab program
I have this Matlab code that create a sinusoidal fit from a set of data
data = importdata('analisipicco.txt') ;
x = data(:,1) ; y = data(:,2) ;
yu = max(y);
yl = min(y);
yr = (yu-yl); ...
0
votes
0
answers
36
views
How to apply OLS with constraints on coefficients and align the output scale with the target variable?
I am working on an OLS regression problem where:
The dependent variable (target) ranges from 1 to 6 (with steps of 1).
The independent variables range from 1 to 10 (with steps of 0.5).
I want to set ...
2
votes
1
answer
154
views
Maximum number of function evaluations has been exceeded - increase MaxFunEvals option
I was trying to fit a data set into a sinusoidal function with the code below:
data = importdata('analisipicco.txt') ;
x = data(:,1) ; y = data(:,2) ;
yu = max(y);
yl = min(y);
yr = (yu-yl); ...
1
vote
1
answer
118
views
Solve (underdetermined) linear system with commutator form in Python
Consider three (complex) square matrices A, X, and B, that form a generally underdetermined linear system
A @ X - X @ A == B
The system is to be solved for X. I would like to use, e.g., the lstsq ...
1
vote
2
answers
184
views
Problem with least squares rational approximation to `asin(x)+ sqrt(1-x^2)` in [3,1] form
I'm trying to generate a decent [3,1] rational least squares polynomial approximation to asin(x)+sqrt(1-x^2) on [0,1] and failing dismally :(
The problem is that it has a pole for this particular ...
0
votes
0
answers
422
views
Using Clarabel as a backend of CVXPY
Is this a bug, or is there something fundamental I'm missing with how to use cvxpy?
Consider this code for a least squares optimisation for a 3 variable vector with 3 measurements:
import scipy
import ...
1
vote
0
answers
34
views
Transferring the excel REGLINW function to php
I wanted to use excel function (REGLINW) in php code to calculate extrapolated.
I tried to use the LeastSquares function (https://php-ml.readthedocs.io/en/latest/machine-learning/regression/least-...
0
votes
0
answers
68
views
While True loop stuck at a certain iteration while trying to optimize for the best curve fit given a data set in python
So basically I wanted to make my own function to fit a curve given a dataset. I generally applied the least square method for the types polynomial, exponential and logarithmic but I noticed that this ...
0
votes
0
answers
44
views
Least squared optimization with SciPy but without smoothing
I'm currently trying to unfold the neutron spectrum using Bonner spheres spectrometry (which is essentially an under-determined problem). I have been using least_squares from scipy.optimize but I'm ...
1
vote
1
answer
108
views
fit the data with two type of fit combined or any one type fit, whichever is good fit
I have data x and y , want to fit one part with power_fit and other part with negative power_fit settling to zero finally and start from some -20nm with some 5nF values and goes down after that minima ...
0
votes
1
answer
138
views
Why do I get negative values for parameters in a curve fitting?
I'm trying to fit modeling data as a curve using Scipy's optimize curve_fit to some scattered data, but I got a negative value of (bX) parameter that makes no sense. So I'm not sure what is wrong with ...
0
votes
1
answer
100
views
How can I vectorize this linalg.lstq() operation?
I am trying to implement a multi-frequency phase unwrapping algorithm using Python3 and NumPy. I have 7 single channel (gray scale) images of shape (1080, 1920). After stacking them along the third ...
0
votes
1
answer
129
views
Can you create an array/vector of arbitrary length in Mathematica/Wolfram language?
I am working on a small proof/demonstration of how the least squares method gives us the arithmetic mean.
Wolfram Language 14.0.0 Engine for Microsoft Windows (64-bit)
Copyright 1988-2023 Wolfram ...
1
vote
3
answers
276
views
Solving non-linear system of equations (issue with sqrt)
I am trying to solve a system of non-linear equations using Python (under-expanded jet with losses - Molkov):
I am trying to use the library Scipy and the module fsolve:
def equations10(p):
u3, ...
0
votes
0
answers
79
views
Bad results while doing linear regression
I was trying to do a multi variate linear regression using a set of data. I tried to predict the Y using the same set of X used to generate the regression coefficients. While the differences between ...
1
vote
1
answer
169
views
Scipy.optimize.least_square sensitive to order of inputs
The following code generate different results depending on the order of the inputs I pass on. Why is that? I'd expect least square optimization to reach same result no matter what order the inputs are ...
3
votes
1
answer
228
views
How to fit axis and radius of 3D cylinder? [duplicate]
Once I get some 3-D point coordinates, what algorithm do I use to fit an optimal cylindrical and get the direction vector and radius of the central axis?
My previous idea was to divide a cylinder ...
0
votes
0
answers
95
views
gls with repeated measures of BMI over time with complex samples (twins) in R
I'm running a generalised least squares (gls) to model BMI trajectories with age by intake of a nutrient. My sample is a cohort of twins, so data are clustered within individuals (twinID; due to ...
0
votes
0
answers
21
views
Least_square method for n=p equations/unknown resolutio: Bounds/constraints not respected on proposed solutions
As a Phd Student, working on non-linear problem i try to find solutions, with physical meanings over the following system:
Input variables are A, B, Cf, Jp, ks, Pp, R,T.
Output variables are : Jw,Js,...
0
votes
1
answer
141
views
numpy Polynomial.fit with degree zero produces unexpected result
import numpy as np
f = np.array(
[481.62900766, 511.94542042, 647.40216379, 686.10402156, 849.9420538, 888.64398048, 1029.26087049, 1071.18799217,
1210.51481107, 1266.63254274, 1409.54282743]...
1
vote
1
answer
106
views
How do I fit an exponential 3D surface to measured data
This is my data:
[[1.0183786345931547, 1.0299586760768078, 1.038641346963767, 1.0450398412805133, 1.194598528164483], [1.0498980141678536, 1.0740481275807727, 1.101990429736493, 1.1528998376687427, 1....
2
votes
0
answers
128
views
Sparse matrix / vector product, how come some code using knowledge about the matrix structure is a lot slower than naïve optimised code?
I have some sparse system of which I know the structure. I implemented a naïve sparse matrix / vector product, which has no informations on the structure of the matrix, and a version of that product ...
1
vote
2
answers
582
views
scipy.optimize.least_squares() runs 5 times and gives back initial guess everytime
I am running the least_squares optimization fit my data against measured values. I have created a cost function and all function parameters seem to be fine, but the result is the exact same as the ...
0
votes
0
answers
99
views
Iteration algorithm in R for least squares estimation of high dimensional regressions
I have a matched employer-employee data set with 20 years of information on around 2.000.000 individuals and 400.000 firms. Amongst several worker- and firm-level covariates, I have worker, firm and ...
1
vote
0
answers
101
views
Computing a piecewise-linear approximation of a function of three variables
Imagine that you have a bunch of points in R3, each with a value (say, temperature). You want to construct a regular grid in R3 and compute a value at each grid point, such that if you then use ...
0
votes
1
answer
128
views
Optimization of fitting parameters of two coupled equations by using least-square method scipy
I want to fit these 4 parameters:
K0 = np.array([K11, K12, K21, K22])
In from the coupled equations f(x, parameters) and g(x, parameters)
We could think those equations are normalized and have a ...
1
vote
1
answer
479
views
Weighted Least Squares in Python
I am trying to do a weighted least squares fit of my data. The values when x=0 and when x>0.2 should be weighted heavily. The values when 0<x<=0.2 should be weighted to a lesser extent but I ...
0
votes
3
answers
465
views
Plot arrow on each point towards the line in graph
I am trying to plot arrows from each data point towards the line in the graph using matplotlib.
I want the arrow to represent the distance between each point and the line. How can I do this?
Here's ...
0
votes
1
answer
367
views
numpy least-squares solution for a matrix with complex elements
I am trying to solve the equation y=a*x. I have three measurements for x (x1,x2,x3) and y (y1,y2,y3) and am trying to find "a" ( the slop). The first important thing is that y and X are ...
0
votes
1
answer
186
views
why my Linear Least-Squares does not fit right the data-points
I'm getting not very fitted 2D-plane with such a code:
import numpy as np
from scipy import linalg as la
from scipy.linalg import solve
# data
f1 = np.array([1., 1.5, 3.5, 4.])
f2 = np.array([3., 4.,...
-1
votes
1
answer
681
views
NDVI double logistic curve fitting in Python
I am trying to do a NDVI double logistic curve fit in Python. This double logistic curve fitting is published by Beck et al. 2006. There is a R package greenbrown which does this over a year, so far I ...
1
vote
2
answers
3k
views
Fitting an ellipse in python
I am very new to coding and I basically only use it for physics related stuff. I have recently been trying to fit an ellipses with data that I have but I have not gotten any result that resembles the ...
1
vote
1
answer
715
views
Fastest way to compute least-squares with relatively sparse matrix (0.4% of data)
Context: I solve the equation A_des.x = b where I find x through a least-squares method. I have to do this operation several thousands of time. A_des changes between each iteration but remains sparse (...
0
votes
0
answers
86
views
How to go from standard deviation to standard error in python least_squares fit?
I am not proficient in statistics. Following a thread: How to compute standard deviation errors with scipy.optimize.least_squares, I got my std to be
std = np.sqrt(np.diagonal(np.linalg.inv(J.T @ J) * ...
0
votes
1
answer
604
views
Sine curve to fit data cloud using C++
Consider:
Curve fit using Python SciPy
I'm trying to find an algorithm to fit a sine curve into a data set. This is quite simple using Python SciPy, but now I have to bring the whole algorithm to an ...
3
votes
2
answers
237
views
Constraining conditional summation in Bounded Optimization in Python
I am trying to minimize a the sum of least squares subject to certain constraints. For the most part, this problem seems fairly straightforward except for one constraint. I'm having a difficult time ...
0
votes
0
answers
585
views
Speeding up function minimisation using Scipy's Powell method
I am trying to solve a nonlinear least squares problem using Scipy's minimize-function in Python. The model is very complicated and (typically) depends on 14 parameters. Thus, I and many symbolic ...
1
vote
1
answer
118
views
Pytorch and SGD coefficients are not matching. What is wrong?
I am working with a use-case where getting the coefficients in the ballpark of the OLS coefficients is important.
What I have below is reproducible code and data which runs through OLS and two ...
1
vote
1
answer
182
views
least_square does not run, residual is less than variables
I'm using scipy.optimize.least_square to try to minimize the residual of function.
Here is the code:
def solido_3parameters(time, strain0, eta1, time0, stiffness2, eta):
return strain0 + (sigma0 / ...
1
vote
2
answers
698
views
Fitting a Globally Monotonically Increasing Polynomial to Data in Python
I have a dataset to which I want to fit a nth degree univariate polynomial in a least squares fashion. The resulting polynomial should be monotonically increasing for all real numbers, not just the ...