public static bool Filter(DateTime nowDate, weka.core.Instance instance = null, weka.core.Instance preInstance = null) { //if (nowDate.DayOfWeek == DayOfWeek.Friday && nowDate.AddDays(7).Month != nowDate.Month) // return true; if (nowDate.DayOfWeek == DayOfWeek.Friday) return true; //var cp = TestParameters2.CandidateParameter; //string symbolPeriod = string.Format("{0}_{1}", cp.MainSymbol, cp.MainPeriod); //ForexDataRows hpdv = DbData.Instance.GetDbData(TestParameters2.TrainStartTime, TestParameters2.TrainEndTime, symbolPeriod, 0, true, cp); //int idx = hpdv.BinarySearch(0, hpdv.Length, WekaUtils.GetTimeFromDate(nowDate)); //if (idx < 1) // return true; //if ((int)hpdv[idx]["spread"] >= 50) // return true; //if (Math.Abs((double)hpdv[idx]["close"] - (double)hpdv[idx-1]["close"]) > 0.0050) // return true; if (instance != null) { if (instance.value(2) > 60) return true; if (Math.Abs((double)instance.value(3) - (double)preInstance.value(3)) > 0.0050) return true; } else { var dt = Feng.Data.DbHelper.Instance.ExecuteDataTable(string.Format("SELECT TOP 2 * FROM {0}_{1} WHERE TIME <= {2} ORDER BY TIME DESC", TestParameters2.CandidateParameter.MainSymbol, TestParameters2.CandidateParameter.MainPeriod, WekaUtils.GetTimeFromDate(nowDate))); if ((int)dt.Rows[0]["spread"] > 50) return true; if ((double)dt.Rows[0]["close"] - (double)dt.Rows[1]["close"] > 0.0050)// && selectedDeal == 0) return true; if ((double)dt.Rows[0]["close"] - (double)dt.Rows[1]["close"] < -0.0050)// && selectedDeal == 1) return true; //if ((double)dt.Rows[0]["MA_10"] - (double)dt.Rows[1]["MA_10"] < 0 && selectedDeal == 0) // return true; //if ((double)dt.Rows[0]["MA_10"] - (double)dt.Rows[1]["MA_10"] > 0 && selectedDeal == 1) // return true; //dt = Feng.Data.DbHelper.Instance.ExecuteDataTable(string.Format("SELECT TOP 1 * FROM {0}_{1} WHERE TIME = {2} ORDER BY TIME", // TestParameters2.CandidateParameter.MainSymbol, TestParameters2.CandidateParameter.MainPeriod, // WekaUtils.GetTimeFromDate(nowDate))); //if ((double)dt.Rows[0]["MACD_12_26_9_M"] >= 0 && selectedDeal == 1) // return true; //if ((double)dt.Rows[0]["MACD_12_26_9_M"] <= 0 && selectedDeal == 0) // return true; //if ((double)dt.Rows[0]["RSI_14"] >= 70 && selectedDeal == 0) // return true; //if ((double)dt.Rows[0]["RSI_14"] <= 30 && selectedDeal == 1) // return true; } return false; }
protected override string instanceToLibsvm(weka.core.Instance inst) { //StringBuffer.__<clinit>(); //StringBuffer buffer = new StringBuffer(new StringBuilder().append("").append(inst.classValue()).toString()); StringBuffer buffer = new StringBuffer(new StringBuilder().append("").append(inst.classValue() - 1).toString()); for (int i = 0; i < inst.numAttributes(); i++) { if ((i != inst.classIndex()) && (inst.value(i) != 0f)) { buffer.append(new StringBuilder().append(" ").append((int)(i + 1)).append(":").append(inst.value(i)).toString()); } } return buffer.toString(); }
private Type GetEnumType(weka.core.Attribute attribute) { var attributeName = attribute.name(); var enumType =_builder.Assembly.GetType(attributeName); if (enumType != null) { return enumType; } // Define a public enumeration with the name "MyEnum" and an underlying type of Integer. EnumBuilder myEnum = _builder.DefineEnum (attributeName, TypeAttributes.Public, typeof(int)); for (int i=0; i<attribute.numValues(); ++i) { var name = attribute.value(i); myEnum.DefineLiteral (name, i); } // Create the enum return myEnum.CreateType (); }
public override double classifyInstance(weka.core.Instance instance) { if (m_instances.numInstances() == 0) return 2; if (m_instances.numAttributes() != instance.numAttributes()) { throw new AssertException("different attribute."); } int n = (instance.numAttributes() - 1) / 2; List<Tuple<int, int>> dist = new List<Tuple<int, int>>(); for (int i = 0; i < m_instances.numInstances(); ++i) { int d1 = 0, d2 = 0; weka.core.Instance instanceI = m_instances.instance(i); for (int j = 0; j < n; ++j) { //d += (int)((instanceI.value(j) - instance.value(j)) * (instanceI.value(j) - instance.value(j))); if (instanceI.value(j) != instance.value(j)) { if (instance.value(j) == 2 || instanceI.value(j) == 2) d1++; else d1 += 4; } } for (int j = n; j < 2*n; ++j) { //d += (int)((instanceI.value(j) - instance.value(j)) * (instanceI.value(j) - instance.value(j))); if (instanceI.value(j) != instance.value(j)) if (instance.value(j) == 2 || instanceI.value(j) == 2) d2++; else d2 += 4; } int c = (int)instanceI.classValue(); //if (c == 0) //{ // if (d1 < n / 4 && d1 < d2) // { // dist.Add(new Tuple<int, int>(d1, c)); // } //} //else if (c == 1) //{ // if (d2 < n / 4 && d2 < d1) // { // dist.Add(new Tuple<int, int>(d2, c)); // } //} //else //{ // throw new AssertException(""); //} dist.Add(new Tuple<int, int>(d1 + d2, c)); } if (dist.Count == 0) return 2; dist.Sort(new Comparison<Tuple<int, int>>((x, y) => { return x.Item1.CompareTo(y.Item1); })); int sum = 0, count = 0; for (int i = 0; i < dist.Count; ++i) { if (dist[i].Item1 < n / 4 * 2 * 4) { if (dist[i].Item2 != 2 && dist[i].Item2 != 3) { sum += dist[i].Item2; count++; } else { } } else break; } if (count == 0) return 2; if (count < m_instances.numInstances() / 30) return 2; return (int)Math.Round((double)sum / count); }
public override double classifyInstance(weka.core.Instance instance) { if (m_instances.numInstances() == 0) return 2; if (m_instances.numAttributes() != instance.numAttributes()) { throw new AssertException("different attribute."); } int n = instance.numAttributes(); List<Tuple<int, int>> dist = new List<Tuple<int, int>>(); for (int i = 0; i < m_instances.numInstances(); ++i) { int d1 = 0, d2 = 0; weka.core.Instance instanceI = m_instances.instance(i); for (int j = 0; j < n; ++j) { //d += (int)((instanceI.value(j) - instance.value(j)) * (instanceI.value(j) - instance.value(j))); if (instanceI.value(j) != instance.value(j)) { d1++; } if (instance.value(j) != 0) { d2++; } } int c = (int)instanceI.classValue(); dist.Add(new Tuple<int, int>(d1, c)); } if (dist.Count == 0) return 2; dist.Sort(new Comparison<Tuple<int, int>>((x, y) => { return x.Item1.CompareTo(y.Item1); })); int sum = 0, count = 0; for (int i = 0; i < dist.Count; ++i) { if (dist[i].Item1 < 4) { sum += dist[i].Item2; count++; } else break; } if (count == 0) return 2; if (count < m_instances.numInstances() / 70) return 2; return (int)Math.Round((double)sum / count); }
/// <summary> /// Draw the dendogram signature for a specific well /// </summary> /// <param name="Well"></param> /// <param name="Size"></param> /// <param name="PosX"></param> /// <param name="PosY"></param> /// <returns>Lenght of the signature</returns> private int DrawSignatureFromInstance(weka.core.Instance CurrentInstance, int Size, int PosX, int PosY) { if (CurrentInstance == null) return 0; int RealIdx = 0; int SizeFont = Size / 4; int ScrollShiftY = this.VerticalScroll.Value; double Min, Max; int ConvertedValue; // g.DrawString("[" + Well.GetPosX() + "x" + Well.GetPosY() + "]", new Font("Arial", 8), Brushes.Black, 15, PosY - ScrollShiftY); Rectangle CurrentRect = new Rectangle(5, PosY, 8, Size); //SolidBrush CurrBrush = new SolidBrush(Colour); // draw the rectangle // g.FillRectangle(CurrBrush, CurrentRect); for (int iDesc = 0; iDesc < CurrentDendo.InfoForHierarchical.ListInstances.numAttributes(); iDesc++) { // if (!GlobalInfo.CurrentScreen.ListDescriptors[iDesc].IsActive()) continue; // specify the rect shape CurrentRect = new Rectangle(PosX + RealIdx * Size, PosY, Size, Size); // specify the color //cDescriptor CurrentDesc = Well.ListDescriptors[iDesc]; byte[][] LUT = cGlobalInfo.CurrentPlateLUT; // CurrentDendo.InfoForHierarchical.UpDateMinMaxDescByDesc(); Min = CurrentDendo.InfoForHierarchical.ListMin[RealIdx]; Max = CurrentDendo.InfoForHierarchical.ListMax[RealIdx]; if (Min == Max) ConvertedValue = 0; else ConvertedValue = (int)(((CurrentInstance.value(iDesc) - Min) * (LUT[0].Length - 1)) / (Max - Min)); if (ConvertedValue >= LUT[0].Length) ConvertedValue = LUT[0].Length - 1; SolidBrush CurrBrush = new SolidBrush(Color.FromArgb(LUT[0][ConvertedValue], LUT[1][ConvertedValue], LUT[2][ConvertedValue])); // draw the rectangle g.FillRectangle(CurrBrush, CurrentRect); RealIdx++; } return PosX + RealIdx * Size; }