# Simple Non Linear Regression Model • ### Question

• Hi,

I am trying to do inference on the model

y_i=A*Exp[b*x_i]+N(0,s)

For parameters, A, b, with S known which is a pretty basic nonlinear regression model, it looks much easier than softmax,  but I can't quite get it to work.  My code is:

```            double[] Xvals=new double[]{1.2,2.0,3.0,4.0,5.0,6.0};
double[] Yvals=new double[]{0.2604256, 0.3105414, 0.3869585, 0.4821799,0.6008332,0.7486843};
Variable<double> A = Variable.Beta(1, 1);
Variable<double> r = Variable.Beta(1, 1);
List<Vector> dataList = new List<Vector>();
Vector[] data = dataList.ToArray();
Range rows = new Range(Xvals.Length);
VariableArray<double> x = Variable.Constant(Xvals,rows).Named("x");
VariableArray<double> power=Variable.Array<double>(rows);
power[rows] =Variable.Exp(x[rows] * r);
VariableArray<double> y =Variable.Array<double>(rows);
y[rows]=power[rows]*A;
y.ObservedValue = Yvals;
InferenceEngine engine = new InferenceEngine(new ExpectationPropagation());
VectorGaussian postW = engine.Infer<VectorGaussian>(r);
Console.WriteLine("Posterior over the weights: " + Environment.NewLine + postW);
But it dies with "Model is not supported with (insert algorithm) due to Facotor.Product(double product, double a, double b).  Anyone know what I am doing wrong?
Tuesday, August 21, 2012 4:50 AM

• Try the following:

```      Variable<int> R = Variable.New<int>().Named("R");
Range r = new Range(R);
Variable<double> A = Variable.GaussianFromMeanAndPrecision(0, 1).Named("A");
Variable<double> b = Variable.GaussianFromMeanAndPrecision(0, 1).Named("r");
VariableArray<double> x = Variable.Array<double>(r).Named("x");
VariableArray<double> y = Variable.Array<double>(r).Named("y");

using (Variable.ForEach(r))
{
var exp = Variable.Exp(b * x[r]).Named("exp");
var Aexp = (A * exp).Named("aexp");
y[r] = Variable.GaussianFromMeanAndPrecision(Aexp, 1.0);
}

double[] Xvals=new double[] { 1.2, 2.0, 3.0, 4.0, 5.0, 6.0 };
double[] Yvals=new double[] { 0.2604256, 0.3105414, 0.3869585, 0.4821799, 0.6008332, 0.7486843 };
R.ObservedValue = Xvals.Length;
x.ObservedValue = Xvals;
y.ObservedValue = Yvals;

InferenceEngine engine = new InferenceEngine(new VariationalMessagePassing());
Gaussian postA = engine.Infer<Gaussian>(A);
Gaussian postb = engine.Infer<Gaussian>(b);
Console.WriteLine("Posterior over A = {0}", postA);
Console.WriteLine("Posterior over b = {0}", postb);
```

• Marked as answer by Wednesday, August 22, 2012 12:52 AM
Tuesday, August 21, 2012 9:47 AM

### All replies

• Try the following:

```      Variable<int> R = Variable.New<int>().Named("R");
Range r = new Range(R);
Variable<double> A = Variable.GaussianFromMeanAndPrecision(0, 1).Named("A");
Variable<double> b = Variable.GaussianFromMeanAndPrecision(0, 1).Named("r");
VariableArray<double> x = Variable.Array<double>(r).Named("x");
VariableArray<double> y = Variable.Array<double>(r).Named("y");

using (Variable.ForEach(r))
{
var exp = Variable.Exp(b * x[r]).Named("exp");
var Aexp = (A * exp).Named("aexp");
y[r] = Variable.GaussianFromMeanAndPrecision(Aexp, 1.0);
}

double[] Xvals=new double[] { 1.2, 2.0, 3.0, 4.0, 5.0, 6.0 };
double[] Yvals=new double[] { 0.2604256, 0.3105414, 0.3869585, 0.4821799, 0.6008332, 0.7486843 };
R.ObservedValue = Xvals.Length;
x.ObservedValue = Xvals;
y.ObservedValue = Yvals;

InferenceEngine engine = new InferenceEngine(new VariationalMessagePassing());
Gaussian postA = engine.Infer<Gaussian>(A);
Gaussian postb = engine.Infer<Gaussian>(b);
Console.WriteLine("Posterior over A = {0}", postA);
Console.WriteLine("Posterior over b = {0}", postb);
• 