data-fitting

Python: fit data to given cosine function

只谈情不闲聊 提交于 2020-01-02 10:33:46
问题 I am trying to simply find best fit for malus's law. I_measured=I_0*(cos(theta)) ^2 When I scatter the plot, it obviously works but with the def form() function I get the error given below. I googled the problem and it seems that this is not the correct way to curvefit a cosine function. given data is .. x_data=x1 in the code below [ 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0, 105.0, 110.0, 115.0, 120.0, 125.0,

Fitting distribution with fixed parameters in SciPy

僤鯓⒐⒋嵵緔 提交于 2019-12-31 02:26:30
问题 Is it possible to fix parameters while fitting distributions in SciPy? For example, this code: import scipy.stats as st xx = st.expon.rvs(size=100) print st.expon.fit(xx, loc=0) results in non-zero location ( loc ). When some parameter is provided to the fit function it is considered as an initial guess. And if it is provided to the constructor ( st.expon(loc=0) ) the distribution becomes "frozen" and can not be used for fitting. 回答1: To fix loc , use the argument floc : print st.expon.fit(xx

How to fit multiple parameters to a differential equation in R?

假如想象 提交于 2019-12-24 17:54:54
问题 With a dataset like this time C 0.1 2.6 0.25 4.817 0.5 6.596 0.75 6.471 1 6.049 1.5 5.314 2 4.611 2.5 4.5 3 4.392 4 4.013 5 3.698 6 3.505 8 3.382 12 2.844 14 2.383 24 1.287 I want to fit this data to a model, which is defined as below twocpt <- function(t, Cc, parms){ with(as.list(parms),{ dC0 <- -k01*C0 dCc <- k01*C0 + k21*Cp -(k12+ke)*Cc dCp <- k12*Cc - k21*Cp list(dCc) }) } I took the reference in this page (http://www.inside-r.org/packages/cran/FME/docs/modCost), and developed the

Creating an efficient function to fit a dataset

Deadly 提交于 2019-12-24 10:01:36
问题 Basically I have a large (could get as large as 100,000-150,000 values) data set of 4-byte inputs and their corresponding 4-byte outputs. The inputs aren't guaranteed to be unique (which isn't really a problem because I figure I can generate pseudo-random numbers to add or xor the inputs with so that they do become unique), but the outputs aren't guaranteed to be unique either (so two different sets of inputs might have the same output). I'm trying to create a function that effectively models

Fitting data points to an ellipse with its center at the origin using R

安稳与你 提交于 2019-12-24 00:37:28
问题 I have a question about fitting ellipses to data with the ellipse center at the origin. I have explored two methods that fit ellipses but generate an arbitrary center unless I manipulate the data with some imaginary mirror points. Method#01 This portion of the script directly comes from this useful post. I'm copying the codes directly here for ease. fit.ellipse <- function (x, y = NULL) { # from: # http://r.789695.n4.nabble.com/Fitting-a-half-ellipse-curve-tp2719037p2720560.html # # Least

scipy.optimize.leastsq returns best guess parameters not new best fit

三世轮回 提交于 2019-12-23 12:24:37
问题 I want to fit a lorentzian peak to a set of data x and y, the data is fine. Other programs like OriginLab fit it perfectly, but I wanted to automate the fitting with python so I have the below code which is based on http://mesa.ac.nz/?page_id=1800 The problem I have is that the scipy.optimize.leastsq returns as the best fit the same initial guess parameters I passed to it, essentially doing nothing. Here is the code. #x, y are the arrays with the x,y axes respectively #defining funcitons def

Chi-square testing for constraining a parameter

↘锁芯ラ 提交于 2019-12-22 12:19:49
问题 I have an important question about the use of chi^2 test to constrain a parameter in cosmology. I appreciate your help. Please do not give this question negative rate (this question is important to me). Assume we have a data file ( data.txt ) concluding 600 data and this data file has 3 columns, first column is redshift(z), second column is observational dL(m_obs) and third column is error(err). As we know chi^2 function is chi^2=(m_obs-m_theo)**2/err**2 #chi^2=sigma((m_obs-m_theo)**2/err**2)

data fitting an ellipse in 3D space

ぃ、小莉子 提交于 2019-12-19 11:39:08
问题 Forum I've got a set of data that apparently forms an ellipse in 3D space (not an ellipsoid, but a curve in 3D). Being inspired by following thread http://au.mathworks.com/matlabcentral/newsreader/view_thread/65773 and with the help from someone ,I manage to get the optimization code running and outputs a set of best parameters x (vector). However, when I try to use this x to replicate the ellipse,the outcomes is a strange straight line in the space. I have been stacked on this for days.,

Why does scipy.optimize.curve_fit not fit to the data?

半腔热情 提交于 2019-12-17 22:18:04
问题 I've been trying to fit an exponential to some data for a while using scipy.optimize.curve_fit but i'm having real difficulty. I really can't see any reason why this wouldn't work but it just produces a strait line, no idea why! Any help would be much appreciated from __future__ import division import numpy from scipy.optimize import curve_fit import matplotlib.pyplot as pyplot def func(x,a,b,c): return a*numpy.exp(-b*x)-c yData = numpy.load('yData.npy') xData = numpy.load('xData.npy') trialX

How can fit the data on temperature/thermal profile?

北慕城南 提交于 2019-12-17 21:14:19
问题 I have a dataset consisting of a certain temperature profile and I wanna fit or map the measurement points on temperature profile which is following: Dwell-time: 30 mins Ramp-time: 1 min Number of periods: 1000 cycles Measure points period: 16 mins Measure points can be happened in either in high regim +150 or low regim -40 Note: The T0 (initial time) is not clear so time reference is not clear eg. T0=0 . I already fetched the data in Pandas DataFrame: import numpy as np import pandas as pd