for the following example I need to read values from a file (no problem) and put it into the method "func (r *Regression) Train(d ...*dataPoint)" as datapoints. This works:
r.Train(
regression.DataPoint(1, []float64{1, 1, 1}),
regression.DataPoint(4, []float64{2, 2, 2}),
regression.DataPoint(9, []float64{3, 3, 3}),
)
but I would like to put it from a loop like this:
for i := 1; i <= 4; i++ {
??? regression.DataPoint(i*i, []float64{i, i, i}), ???
}
I can not use an array of dataPoint as it is only visible in that package. Here is the full source code:
https://github.com/sajari/regression (see example usage)
Thank you very much,
Maciej
From the page you linked:
Note: You can also add data points one by one.
Therefore you need:
for i := 1; i <= 4; i++ {
r.Train(regression.DataPoint(i*i, []float64{i, i, i}))
}
@Milo's answer is probably best for your particular case, but for the general case with variadic functions, you can append elements to a slice, then use the slice as the variadic argument list:
r.Train(points...)
Unfortunately the regression library is not very well-designed, as it has publicly-exposed functions that receive and return unexposed types, leaving you no way to work with them.