/// <summary> /// 値の計算。 /// </summary> public virtual ValueType this[VariableTable t] { get { return(this.GetValue(t.GetParameterList())); } }
/// <summary> /// 値の計算。 /// </summary> public virtual ValueType this[VariableTable t] { get { return this.GetValue(t.GetParameterList()); } }
/// <summary> /// 指定した範囲内/刻み幅で、関数 f の値が最小になるような引数を探す。 /// (総当り) /// </summary> /// <param name="f">関数 f</param> /// <param name="rangeList">探索範囲/刻み幅</param> /// <returns>argmin f</returns> public static VariableTable Argmin(Function f, params Range[] rangeList) { VariableTable vars = new VariableTable(); foreach (Range range in rangeList) { vars[range.variable] = range.min; } ValueType min = ValueType.MaxValue; VariableTable argmin = null; for (;;) { ValueType val = f[vars]; if (val < min) { min = val; argmin = vars.Clone(); } int i = 0; for (; i < rangeList.Length; ++i) { ValueType x = vars[rangeList[i].variable]; x += rangeList[i].step; if (x > rangeList[i].max) { vars[rangeList[i].variable] = rangeList[i].min; } else { vars[rangeList[i].variable] = x; break; } } if (i >= rangeList.Length) { break; } } return(argmin); }
/// <summary> /// 指定した範囲内/刻み幅で、関数 f の値が最小になるような引数を探す。 /// (総当り) /// </summary> /// <param name="f">関数 f</param> /// <param name="rangeList">探索範囲/刻み幅</param> /// <returns>argmin f</returns> public static VariableTable Argmin(Function f, params Range[] rangeList) { VariableTable vars = new VariableTable(); foreach(Range range in rangeList) { vars[range.variable] = range.min; } ValueType min = ValueType.MaxValue; VariableTable argmin = null; for(;;) { ValueType val = f[vars]; if(val < min) { min = val; argmin = vars.Clone(); } int i=0; for(; i<rangeList.Length; ++i) { ValueType x = vars[rangeList[i].variable]; x += rangeList[i].step; if(x > rangeList[i].max) { vars[rangeList[i].variable] = rangeList[i].min; } else { vars[rangeList[i].variable] = x; break; } } if(i >= rangeList.Length) break; } return argmin; }