本文整理汇总了C#中Vector.Mean方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Mean方法的具体用法?C# Vector.Mean怎么用?C# Vector.Mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.Mean方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValue
/// <summary>
/// Calculates threshold value.
/// </summary>
/// <param name="importances">Feature importances.</param>
/// <returns>Threshold value.</returns>
public double GetValue(Vector<double> importances)
{
switch(name)
{
case "mean":
return importances.Mean()*scale;
case "median":
return importances.Median() * scale;
case "value":
return value;
default:
throw new ArgumentException("Invalid value");
}
}
示例2: Simulate
internal unsafe void Simulate(double m, out List<double> dates, out List<double> finalRate, out List<double> avgRate)
{
List<double> avg = new List<double>();
dates = new List<double>();
finalRate = new List<double>();
avgRate = new List<double>();
Vector r = new Vector(P);
double* _r = r.Buffer;
double dt = m / I;
double rdt = Math.Sqrt(dt);
for (int i = 0; i < I; i++)
{
double theta = Theta(i * dt, dt);
for (int p = 0; p < P; p++)
_r[i] += (theta - a * _r[p]) * dt + sigma * epsilon[p, i] * rdt;
finalRate.Add(r.Mean());
avgRate.Add(((Vector)(finalRate.ToArray())).Mean());
dates.Add(i * dt);
}
return;
}
示例3: CalculateConditional
internal double CalculateConditional(Vector y, Vector x)
{
if (x == null && y == null)
throw new InvalidOperationException("x and y do not exist!");
var values = x.Distinct();
var valueCount = values.Count();
double result = 0;
// binary split
if (Width == 2)
{
// do binary split based on mean
var mean = x.Mean();
var ltSlice = y.Slice(x.Indices(d => d < mean));
var gtSlice = y.Slice(x.Indices(d => d >= mean));
var lh = Calculate(ltSlice);
var rh = Calculate(gtSlice);
result = (0.5 * lh) + (0.5 * rh);
SplitValues = new double[] { x.Min(), mean, x.Max() + 1 };
}
// if valueCount has more values than
// width allows, segment out data to
// fit width
else if (valueCount > Width)
{
double p = 0;
double h = 0;
// create segmentation
// should really consider
// some kind of distribution
// for doing segmentation..
SplitValues = x.Segment(Width);
// for convenience ;)
SplitValues[SplitValues.Length - 1] += 1;
for (int i = 1; i < SplitValues.Length; i++)
{
// get slice
var s = x.Indices(d => d >= SplitValues[i - 1] && d < SplitValues[i]);
// probability of slice
p = s.Count() / (double)x.Length;
// Impurity (y | x_i)
h = Calculate(y.Slice(s));
// sum up
result += p * h;
}
}
// otherwise perform regular counting
// exercises to find cond entropy
else
{
double p = 0;
double h = 0;
// says there is no width
// since deterministic
// slice values
_width = 0;
SplitValues = new double[valueCount];
int k = -1;
// each disting x value
foreach (var i in values)
{
SplitValues[++k] = i;
// get slice
var s = x.Indices(d => d == i);
// probability of x_i
p = s.Count() / (double)x.Length;
// Impurity (y | x_i)
h = Calculate(y.Slice(s));
// sum up
result += p * h;
}
}
return result;
}
示例4: btnOK_Click
private void btnOK_Click(object sender, EventArgs e)
{
Process();
Vector new_data = new Vector(mNewVariableData.Count);
if (cbRemoveMean.Checked)
{
int cnt = 0;
foreach (int key in mNewVariableData.Keys)
{
if (mNewVariableData[key].HasValue)
{
new_data.Values[cnt] = mNewVariableData[key].Value;
cnt++;
}
}
Dictionary<int, double?> data = new Dictionary<int, double?>();
foreach (int k in mNewVariableData.Keys)
{
if (mNewVariableData[k].HasValue)
{
data.Add(k, mNewVariableData[k] - new_data.Mean());
}
else
{
data.Add(k, null);
}
}
mNewVariableData = data;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
示例5: vARIABLESBindingSource_CurrentChanged
private void vARIABLESBindingSource_CurrentChanged(object sender, EventArgs e)
{
try
{
TVec dy = null;
TVec dx = null;
variablesChart.Series.Clear();
variablesChart.Series.Add(new Steema.TeeChart.Styles.FastLine());
if (!((vARIABLESBindingSource.Current as DataRowView).Row as MainDataSet.VARIABLESRow).IsDESCRIPTIONNull())
{
variablesChart.Header.Text = ((vARIABLESBindingSource.Current as DataRowView).Row as MainDataSet.VARIABLESRow).DESCRIPTION;
}
variablesChart.Axes.Left.Title.Text = "Y";
variablesChart.Axes.Bottom.Title.Text = "";
variablesChart.Axes.Left.Automatic = true;
MainDataSet.OBSERVATIONSDataTable tblObservations = oBSERVATIONSTableAdapter.GetDataByVariable(((vARIABLESBindingSource.Current as DataRowView).Row as MainDataSet.VARIABLESRow).ID);
Vector timeseries = new Vector(tblObservations.Rows.Count);
Vector abs = new Vector(tblObservations.Rows.Count);
int cnt = 0;
foreach (DataRow drv in tblObservations.Rows)
{
try
{
timeseries.Values[cnt] = (drv as MainDataSet.OBSERVATIONSRow).VALUE;
}
catch
{
timeseries.Values[cnt] = 0.0;
}
abs.Values[cnt] = (drv as MainDataSet.OBSERVATIONSRow).COUNTER ;
cnt++;
}
dy = timeseries;
dx = abs;
Dew.Math.Tee.TeeChart.DrawValues(dx, dy, variablesChart.Series[0], false);
string FmtString = "0.0000";
double sd = timeseries.StdDev();
string st = "";
st = "size:\t" + timeseries.Length.ToString() + "\r\n";
st += "mean:\t" + Math387.FormatSample(FmtString, timeseries.Mean()) + "\r\n";
st += "std.dev:\t" + Math387.FormatSample(FmtString, sd) + "\r\n";
st += "variance:\t" + Math387.FormatSample(FmtString, sd * sd) + "\r\n";
txtSeriesStats.Text = st;
}
catch { };
}