C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Fitting user defined function with MPFIT in IDL

Date : November 22 2020, 03:01 PM
this will help I am trying to fit a decaying exponential function of the form: A1 - A1exp(-x/A2) to a set of (x,y) values with error bars on y values. I am using the IDL MPFIT function to perform this non linear fit. , The calling sequence for MPFITFUN is
code :
``````result = MPFITFUN('gfunct', xsig, ysig, err, A)
``````

Share :

## User-specified function in mpfit

By : Mlmlte
Date : March 29 2020, 07:55 AM
I wish did fix the issue. There are fitting functions built into SciPy but I do not know of any which account for uncertainties in data as MPFITFUN does. I have found Sherpa to be an excellent modeling and fitting package for Python which accounts for uncertainties and replaces MPFITFUN: http://cxc.harvard.edu/contrib/sherpa/
Since Sherpa is produced by astronomers it has a lot of built in astrophysical models, but you can build your own function to fit with Sherpa's Levenberg-Marquardt, Nelder-Mead or Monte Carlo algorithms. I used the template from the pysherpa blog: http://pysherpa.blogspot.com/2010/06/user-defined-sherpa-model-types-using.html

## Problems with MPFIT and user-defined derivatives

By : Anat Joda
Date : March 29 2020, 07:55 AM
hop of those help? Because the calculation of the residuals is (DATA-MODEL)/SIGMA, the derivatives should be:
[-d(MODEL)/d(PARAM)]/sigma.
code :
``````derivs[j][i] = foo;
``````
``````derivs[j][i] = -foo/ey[i];
``````

## Cassandra: How to reference a field in user defined type in a user defined function (Java)

By : 王永志
Date : March 29 2020, 07:55 AM
wish help you to fix your issue In Java the UDT variable is represented by the class com.datastax.driver.core.UDTValue. This class has get and set methods. There are methods using an index (0 ...) to identify the fields (in the order they are defined in the UDT), and methods that use the field name.
See API Doc.
code :
``````TupleValue accumState = state.getTupleValue( "accum");
String prevSource = accumState.getString( 0);
Map<String,Double> avgMap = state.getMap( "avg_map", String.class, Double.class);
``````
``````accumState.setDouble( 2, value);
state.setTupleValue( "accum", accumState);
``````
``````// does not work
state.getTupleValue( "accum").setDouble( 2, value);
``````
``````// sums up until the source changes, then adds the avg to the map
// IMPORTANT: table must be ordered by source
CREATE OR REPLACE FUNCTION average_by_source_1( state avg_type_1, source text, value double)
CALLED ON NULL INPUT
RETURNS avg_type_1
LANGUAGE java
AS \$\$

TupleValue accumState = state.getTupleValue( "accum");
String prevSource = accumState.getString( 0);

// when no source yet, save the first source, set the count to 1, and set the value
if (prevSource == null) {
accumState.setString( 0, source);
accumState.setInt( 1, 1);
accumState.setDouble( 2, value);
state.setTupleValue( "accum", accumState);
}

// when same source, increment the count and add the value
else if (prevSource.equals( source)) {
accumState.setInt( 1, accumState.getInt( 1) + 1);
accumState.setDouble( 2, accumState.getDouble( 2) + value);
state.setTupleValue( "accum", accumState);
}

// when different source, calc average and copy to map, then re-init accumulation
else if (accumState.getInt( 1) > 0) {
double avgVal = accumState.getDouble( 2) / accumState.getInt( 1);
Map<String,Double> mapState = state.getMap( "avg_map", String.class, Double.class);
mapState.put( prevSource, avgVal);
state.setMap( "avg_map", mapState, String.class, Double.class);
accumState.setString( 0, source);
accumState.setInt( 1, 1);
accumState.setDouble( 2, value);
state.setTupleValue( "accum", accumState);
}

// should not happen - prev case uses "if" to avoid division by zero
else {
Map<String,Double> mapState = state.getMap( "avg_map", String.class, Double.class);
mapState.put( "ERROR: div by zero", null);
accumState.setString( 0, source);
accumState.setInt( 1, 1);
accumState.setDouble( 2, value);
state.setTupleValue( "accum", accumState);
}

// IMPROTANT: final function must calculate the average for the last source and
//            add it to the map.

return state;

\$\$
;
``````

## Call a user defined function defined in schemaA from a view defined in SchemaB SQL Server

By : Screamzz
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am having a problem to call a function from my view. They are both in different schemas, so I have something like this: , Your function should be schema bound (WITH SCHEMABINDING):
code :
``````CREATE FUNCTION SchemaBinded(@INPUT INT)
RETURNS INT WITH SCHEMABINDING
BEGIN
RETURN @INPUT * 2 + 50
END
GO
``````

## Why does scipy.optimize.curve_fit() perform better with a defined number of aruments in fitting function?

By : user3676418
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It works actually the same, the problem is that the second definition of fit does not work for numpy arrays, since np.sum will always result in a single number. Just specify the axis and it will work:
code :
``````import scipy.optimize as optimize

def fit(x, a, b):
return a + b*x

def fit2(x, *args):
return np.sum([arg * x**i for i, arg in enumerate(args)], axis=0)

x_data = np.linspace(-0.3, 0.3, 200)
y_data = x_data * 1000 + np.random.normal(size=x_data.shape[0], scale=20)

my_fit = optimize.curve_fit(fit, x_data, y_data, p0=[1, 1])
my_fit2 = optimize.curve_fit(fit2, x_data, y_data, p0=[1, 1])

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 5))
ax1.scatter(x_data, y_data, alpha=0.5, color='red')
ax1.plot(x_data, fit(x_data, my_fit[0][0], my_fit[0][1]), color='k')
ax2.scatter(x_data, y_data, alpha=0.5, color='red')
ax2.plot(x_data, fit2(x_data, my_fit2[0][0], my_fit2[0][1]), color='k')
``````