void AllPlot() { if (section <= 48) { MessageBox.Show("时间序列过短,无法进行SARIMA预测"); } if (band[0] == 0) { MessageBox.Show("您选择的地点是陆地或没有数据,请重新查询"); } else { MWNumericArray band_m = new MWNumericArray(MWArrayComplexity.Real, 1, section); MWCellArray time_m = new MWCellArray(section); MWArray result; for (int i = 0; i < section; i++) { band_m[i + 1] = band[i]; time_m[i + 1] = time[i]; } if (section <= 36) { result = plot_all.series_all(band_m, time_m, 1, section); } else { result = plot_all.series_all(band_m, time_m, 0, section); } List <string> temp = new List <string>(); foreach (var item in result.ToArray()) { temp.Add(item.ToString()); } Std = Convert.ToDouble(temp[0]); pq.Add(Convert.ToDouble(2)); pq.Add(Convert.ToDouble(2)); it = new ListViewItem(); it.Text = "Std"; it.SubItems.Add(Std.ToString()); listView2.Items.Add(it); it = new ListViewItem(); it.Text = "p"; it.SubItems.Add(pq[0].ToString()); listView2.Items.Add(it); it = new ListViewItem(); it.Text = "q"; it.SubItems.Add(pq[1].ToString()); listView2.Items.Add(it); button2.Enabled = true; } }
/// <summary> /// Calculates the edge features vector of the current image /// </summary> public List <Feature> EdgeFeaturesVector(int X, int Y, int W, int H) { List <Feature> FV = new List <Feature>(); try { MWArray res = new MWCellArray(37, 1); res = FEC.CannyEdgeHistogram(this.imagePath, X, Y, W, H); FV.Add(new Feature("Edge1", double.Parse(res[1].ToString()))); FV.Add(new Feature("Edge2", double.Parse(res[2].ToString()))); FV.Add(new Feature("Edge3", double.Parse(res[3].ToString()))); FV.Add(new Feature("Edge4", double.Parse(res[4].ToString()))); FV.Add(new Feature("Edge5", double.Parse(res[5].ToString()))); FV.Add(new Feature("Edge6", double.Parse(res[6].ToString()))); FV.Add(new Feature("Edge7", double.Parse(res[7].ToString()))); FV.Add(new Feature("Edge8", double.Parse(res[8].ToString()))); FV.Add(new Feature("Edge9", double.Parse(res[9].ToString()))); FV.Add(new Feature("Edge10", double.Parse(res[10].ToString()))); FV.Add(new Feature("Edge11", double.Parse(res[11].ToString()))); FV.Add(new Feature("Edge12", double.Parse(res[12].ToString()))); FV.Add(new Feature("Edge13", double.Parse(res[13].ToString()))); FV.Add(new Feature("Edge14", double.Parse(res[14].ToString()))); FV.Add(new Feature("Edge15", double.Parse(res[15].ToString()))); FV.Add(new Feature("Edge16", double.Parse(res[16].ToString()))); FV.Add(new Feature("Edge17", double.Parse(res[17].ToString()))); FV.Add(new Feature("Edge18", double.Parse(res[18].ToString()))); FV.Add(new Feature("Edge19", double.Parse(res[19].ToString()))); FV.Add(new Feature("Edge20", double.Parse(res[20].ToString()))); FV.Add(new Feature("Edge21", double.Parse(res[21].ToString()))); FV.Add(new Feature("Edge22", double.Parse(res[22].ToString()))); FV.Add(new Feature("Edge23", double.Parse(res[23].ToString()))); FV.Add(new Feature("Edge24", double.Parse(res[24].ToString()))); FV.Add(new Feature("Edge25", double.Parse(res[25].ToString()))); FV.Add(new Feature("Edge26", double.Parse(res[26].ToString()))); FV.Add(new Feature("Edge27", double.Parse(res[27].ToString()))); FV.Add(new Feature("Edge28", double.Parse(res[28].ToString()))); FV.Add(new Feature("Edge29", double.Parse(res[29].ToString()))); FV.Add(new Feature("Edge30", double.Parse(res[30].ToString()))); FV.Add(new Feature("Edge31", double.Parse(res[31].ToString()))); FV.Add(new Feature("Edge32", double.Parse(res[32].ToString()))); FV.Add(new Feature("Edge33", double.Parse(res[33].ToString()))); FV.Add(new Feature("Edge34", double.Parse(res[34].ToString()))); FV.Add(new Feature("Edge35", double.Parse(res[35].ToString()))); FV.Add(new Feature("Edge36", double.Parse(res[36].ToString()))); FV.Add(new Feature("Edge37", double.Parse(res[37].ToString()))); return(FV); } catch (Exception ex) { return(null); } }
public MWCellArray NetListToMLCellArray(List<Double[,]> input ) { MWCellArray cellArray = new MWCellArray(input.Count); // MWNumericArray numericArray = new MWNumericArray(); for (int i = 1; i < input.Count+1; i++) { cellArray[i] = ((MWNumericArray)input[i-1]); } return cellArray; }
public float MatlabQPeek(List <float> zposList, List <byte[, ]> bytelist, int max_cnt, ref float z_pos1, ref float z_pos2, ref float z_pos3, ref float new_z_pos_m, bool bDirty, ref int bFineFlag) { DateTime starT = DateTime.Now; int loop_cnt = 0; float rect_cnt = 0; float rect = 0; try { MWCellArray mwcell = new MWCellArray(max_cnt, 1); for (int i = 0; i < max_cnt; i++) { MWNumericArray mwarr = bytelist[i]; mwcell[i + 1, 1] = mwarr; } MWNumericArray mwz = zposList.ToArray(); loop_cnt = bDirty == false ? 0 : 1; MWNumericArray mwCnt = loop_cnt; //MWArray mwret = this.qFocus.QuickFocusOfSinglePointROIForDll(mwz, mwcell); MWArray mwret = this.qfprep.QuickFocusOfSinglePointROIForDll(mwz, mwcell, mwCnt); float[,] ret = (float[, ])((MWNumericArray)mwret).ToArray(MWArrayComponent.Real); z_pos1 = ret[0, 0]; z_pos2 = ret[0, 1]; z_pos3 = ret[0, 2]; new_z_pos_m = ret[0, 3]; bFineFlag = (int)ret[0, 4]; z_pos1 = z_pos1 > 0.4 ? 0 : z_pos1; z_pos2 = z_pos2 > 0.4 ? 0 : z_pos2; z_pos3 = z_pos3 > 0.4 ? 0 : z_pos3; if (rect_cnt == 1) { loop_cnt++; } else { loop_cnt = 0; } rect = new_z_pos_m; } catch (Exception ex) { LogHelper.AppLoger.Error(ex); } finally { } return(rect); }
public void MatlabFitting(Dictionary <Point, float> dicMap) { try { int max = dicMap.Count; double[,] dbx = new double[max, 3]; MWCellArray mwary = new MWCellArray(max, 3); List <Point> lst = new List <Point>(dicMap.Keys); StringBuilder strDat = new StringBuilder(); for (int i = 0; i < lst.Count; i++) { Point p = lst[i]; float v = dicMap[p]; //float[] fv = new float[3] { (float)p.X, (float)p.Y, v }; dbx[i, 0] = (double)p.X; dbx[i, 1] = (double)p.Y; dbx[i, 2] = (double)v; strDat.AppendFormat("{0},{1},{2}", p.X, p.Y, v); strDat.AppendFormat(System.Environment.NewLine); } //save result to file string path = @"c:\map\"; if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } var utf8WithoutBom = new System.Text.UTF8Encoding(true); FileStream fs = new FileStream(path + "final_data.csv", FileMode.Create); StreamWriter sw = new StreamWriter(fs, utf8WithoutBom); sw.Write(strDat.ToString()); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); MWNumericArray x = new MWNumericArray(dbx); MWArray mwret = this.gfPrep.PreMapFunction(x); //float[,] ret = (float[,])((MWNumericArray)mwret).ToArray(MWArrayComponent.Real); } catch (Exception ex) { LogHelper.AppLoger.Error(ex); } }
private float MatlabPeek(List <float> zposList, List <byte[, ]> bytelist, int max_cnt) { MWCellArray mwcell = new MWCellArray(max_cnt, 1); for (int i = 0; i < max_cnt; i++) { MWNumericArray mwarr = bytelist[i]; mwcell[i + 1, 1] = mwarr; } MWNumericArray mwz = zposList.ToArray(); MWArray mwret = this.myDll2.GlobalFocusOfSinglePointROIForDll(mwz, mwcell); float[,] ret = (float[, ])((MWNumericArray)mwret).ToArray(MWArrayComponent.Real); float new_z_pos_m = ret[0, 0]; return(new_z_pos_m); }
/// <summary> /// Calculates the texture features vector of the current image /// </summary> public List <Feature> TextureFeaturesVector(int X, int Y, int W, int H) { List <Feature> FV = new List <Feature>(); try { MWArray res = new MWCellArray(24, 1); res = FEC.ExtractTextureInfo(this.imagePath, X, Y, W, H); FV.Add(new Feature("TexContrast0", double.Parse(res[1].ToString()))); FV.Add(new Feature("TexCorrelation0", double.Parse(res[2].ToString()))); FV.Add(new Feature("TexEnergy0", double.Parse(res[3].ToString()))); FV.Add(new Feature("TexHomogeneity0", double.Parse(res[4].ToString()))); FV.Add(new Feature("TexEntropy0", double.Parse(res[5].ToString()))); FV.Add(new Feature("TexMax0", double.Parse(res[6].ToString()))); FV.Add(new Feature("TexContrast45", double.Parse(res[7].ToString()))); FV.Add(new Feature("TexCorrelation45", double.Parse(res[8].ToString()))); FV.Add(new Feature("TexEnergy45", double.Parse(res[9].ToString()))); FV.Add(new Feature("TexHomogeneity45", double.Parse(res[10].ToString()))); FV.Add(new Feature("TexEntropy45", double.Parse(res[11].ToString()))); FV.Add(new Feature("TexMax45", double.Parse(res[12].ToString()))); FV.Add(new Feature("TexContrast90", double.Parse(res[13].ToString()))); FV.Add(new Feature("TexCorrelation90", double.Parse(res[14].ToString()))); FV.Add(new Feature("TexEnergy90", double.Parse(res[15].ToString()))); FV.Add(new Feature("TexHomogeneity90", double.Parse(res[16].ToString()))); FV.Add(new Feature("TexEntropy90", double.Parse(res[17].ToString()))); FV.Add(new Feature("TexMax90", double.Parse(res[18].ToString()))); FV.Add(new Feature("TexContrast135", double.Parse(res[19].ToString()))); FV.Add(new Feature("TexCorrelation135", double.Parse(res[20].ToString()))); FV.Add(new Feature("TexEnergy135", double.Parse(res[21].ToString()))); FV.Add(new Feature("TexHomogeneity135", double.Parse(res[22].ToString()))); FV.Add(new Feature("TexEntropy135", double.Parse(res[23].ToString()))); FV.Add(new Feature("TexMax135", double.Parse(res[24].ToString()))); return(FV); } catch (Exception ex) { return(null); } }
static void Main(string[] args) { // get data table DataTable table = getData(); // create the MWCellArray int numRows = table.Rows.Count; int numCols = table.Columns.Count; MWCellArray cell = new MWCellArray(numRows, numCols); // one-based indices // fill it cell-by-cell for (int r = 0; r < numRows; r++) { for (int c = 0; c < numCols; c++) { // fill based on type Type t = table.Columns[c].DataType; if (t == typeof(DateTime)) { //cell[r+1,c+1] = new MWNumericArray( convertToMATLABDateNum((DateTime)table.Rows[r][c]) ); cell[r + 1, c + 1] = convertToMATLABDateNum((DateTime)table.Rows[r][c]); } else if (t == typeof(string)) { //cell[r+1,c+1] = new MWCharArray( (string)table.Rows[r][c] ); cell[r + 1, c + 1] = (string)table.Rows[r][c]; } else { //cell[r+1,c+1] = new MWNumericArray( (double)table.Rows[r][c] ); cell[r + 1, c + 1] = (double)table.Rows[r][c]; } } } // call MATLAB function CellClass obj = new CellClass(); obj.my_cell_function(cell); // Wait for user to exit application Console.ReadKey(); }
public float MatlabPeek(List <float> zPosList, List <byte[, ]> byteList, int maxCnt) { float rect = 0; try { MWCellArray mwcell = new MWCellArray(maxCnt, 1); for (int i = 0; i < maxCnt; i++) { MWNumericArray mwarr = byteList[i]; mwcell[i + 1, 1] = mwarr; } MWNumericArray mwz = zPosList.ToArray(); MWArray mwret = this.gfPrep.GlobalFocusOfSinglePointROIForDll(mwz, mwcell); float[,] ret = (float[, ])((MWNumericArray)mwret).ToArray(MWArrayComponent.Real); float new_z_pos_m = ret[0, 0]; rect = new_z_pos_m; } catch (Exception ex) { LogHelper.AppLoger.Error(ex); } return(rect); }
/// <summary> /// Calculates the shape features vector of the current image /// </summary> public List <Feature> ShapeFeaturesVector(int X, int Y, int W, int H) { List <Feature> FV = new List <Feature>(); try { MWArray res = new MWCellArray(7, 1); res = FEC.ExtractShapeInfo(this.imagePath, X, Y, W, H); FV.Add(new Feature("ShapeM1", double.Parse(res[1].ToString()))); FV.Add(new Feature("ShapeM2", double.Parse(res[2].ToString()))); FV.Add(new Feature("ShapeM3", double.Parse(res[3].ToString()))); FV.Add(new Feature("ShapeM4", double.Parse(res[4].ToString()))); FV.Add(new Feature("ShapeM5", double.Parse(res[5].ToString()))); FV.Add(new Feature("ShapeM6", double.Parse(res[6].ToString()))); FV.Add(new Feature("ShapeM7", double.Parse(res[7].ToString()))); return(FV); } catch (Exception ex) { return(null); } }
public List <Vector3d> ICPCalculation(List <Vector3d> pointsToTransform, List <Vector3d> pointsOrig) { int j = 0; int m = 0; double[,] map_points = new double[3, pointsToTransform.Count]; for (int i = 0; i < map_points.Length / 3; i++, j++) { map_points.SetValue(pointsToTransform[i].X, 0, j); map_points.SetValue(pointsToTransform[i].Y, 1, j); map_points.SetValue(pointsToTransform[i].Z, 2, j); } double[,] map_pointsToTransform = ThinPointCloud(pointsToTransform, 0, 50); m += 10; double[,] map_pointsOrig = new double[3, pointsOrig.Count()]; for (int i = 0; i < pointsOrig.Count; i++) { map_pointsOrig.SetValue(pointsOrig[i].X, 0, i); map_pointsOrig.SetValue(pointsOrig[i].Y, 1, i); map_pointsOrig.SetValue(pointsOrig[i].Z, 2, i); } //IterativeClosestPointClass icp = new IterativeClosestPointClass(); ICP icpTest = new ICP(); // ICP icpTest = new ICP(); MWCellArray outMapedPointsNew = null; MWCellArray outMapedPointsOld = null; Console.WriteLine("Start of ICP algorithm"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); outMapedPointsNew = (MWCellArray)icpTest.getIterativeClosestPoints((MWNumericArray)map_pointsOrig, (MWNumericArray)map_pointsToTransform, (MWNumericArray)map_points, (MWNumericArray)20); for (int i = 0; i < 5; i++) { m += 5; MWNumericArray newoutmappedPoints = (MWNumericArray)outMapedPointsNew[1]; List <Vector3d> newPoints = new List <Vector3d>(); double newx, newy, newz; Vector3d newact_point; for (int k = 1; k < newoutmappedPoints.Dimensions[1]; k++) { newx = (double)newoutmappedPoints[1, k]; newy = (double)newoutmappedPoints[2, k]; newz = (double)newoutmappedPoints[3, k]; newact_point = new Vector3d(newx, newy, newz); newPoints.Add(newact_point); } map_pointsToTransform = ThinPointCloud(newPoints, m, 50); outMapedPointsOld = outMapedPointsNew; // Call function getIterativeClosestPoints which returns a new Array of map_points with rotation and translation //outMapedPoints= (MWCellArray)icp.getIterativeClosestPoints((MWNumericArray)map_pointsOrig, (MWNumericArray)map_points, (MWNumericArray)map_pointsToTransform,(MWNumericArray)15); outMapedPointsNew = (MWCellArray)icpTest.getIterativeClosestPoints((MWNumericArray)map_pointsOrig, (MWNumericArray)map_pointsToTransform, outMapedPointsOld[1], (MWNumericArray)30); } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; Console.WriteLine("End of ICP algorithm, it took : {0} minuts and {1} seconds!", ts.Minutes, ts.Seconds); MWNumericArray mappedPoints = (MWNumericArray)outMapedPointsNew[1]; MWNumericArray rotation_vec = (MWNumericArray)outMapedPointsNew[2]; MWNumericArray translation_vec = (MWNumericArray)outMapedPointsNew[3]; Vector3d act_point; List <Vector3d> points = new List <Vector3d>(); double x, y, z; for (int i = 1; i <= mappedPoints.Dimensions[1]; i++) { x = (double)mappedPoints[1, i]; y = (double)mappedPoints[2, i]; z = (double)mappedPoints[3, i]; act_point = new Vector3d(x, y, z); points.Add(act_point); } List <Vector4d> matrix = new List <Vector4d>(); Vector4d column; for (int i = 1; i < 4; i++) { x = (double)mappedPoints[1, i]; y = (double)mappedPoints[2, i]; z = (double)mappedPoints[3, i]; column = new Vector4d((double)rotation_vec[i, 1], (double)rotation_vec[i, 2], (double)rotation_vec[i, 3], (double)translation_vec[i, 1]); matrix.Add(column); } column = new Vector4d(0, 0, 0, 1); matrix.Add(column); //WriteTransformationMatrix(matrix, "..\\..\\..\\..\\..\\03Daten\\registratedData\\MeshTomo_to_SimulatedTransformation.txt"); transMatrix = matrix; //GetNearestPoints(points, pointsOrig); return(points); }
public List <int> GetNearestPoints(List <Vector3d> points, List <Vector3d> pointsOrig, Dictionary <String, List <float> > scalarDataRegistratedPoints, Dictionary <String, List <float> > scalarDataOriginalPoints) { //Dictionary<string, List<float>>.KeyCollection KeyCollRegistrated = scalarDataRegistratedPoints.Keys; //int nKeysRegistrated = KeyCollRegistrated.Count(); //Dictionary<string, List<float>>.KeyCollection KeyCollOriginal = scalarDataOriginalPoints.Keys; //int nKeysOriginal = KeyCollOriginal.Count(); //List<float> scalarValuesX = new List<float>(); //scalarDataOriginalPoints.TryGetValue(KeyCollOriginal.ElementAt<string>(0), out scalarValuesX); //List<float> scalarValuesY = new List<float>(); //scalarDataOriginalPoints.TryGetValue(KeyCollOriginal.ElementAt<string>(1), out scalarValuesY); //List<float> scalarValuesZ = new List<float>(); //scalarDataOriginalPoints.TryGetValue(KeyCollOriginal.ElementAt<string>(2), out scalarValuesZ); //// create vectorfield //List<Vector3d> vectorFielRegistratedPoints = new List<Vector3d>(); //for (int i = 0; i < scalarValuesX.Count(); i++) //{ // Vector3d vec = new Vector3d(scalarValuesX[i], scalarValuesY[i], scalarValuesZ[i]); // vectorFielRegistratedPoints.Add(vec); //} //scalarDataRegistratedPoints.TryGetValue("x_velocity", out scalarValuesX); //scalarDataRegistratedPoints.TryGetValue("y_velocity", out scalarValuesY); //scalarDataRegistratedPoints.TryGetValue("z_velocity", out scalarValuesZ); //// create vectorfield //List<Vector3d> vectorFielOriginalPoints = new List<Vector3d>(); //for (int i = 0; i < scalarValuesX.Count(); i++) //{ // Vector3d vec = new Vector3d(scalarValuesX[i], scalarValuesY[i], scalarValuesZ[i]); // vectorFielOriginalPoints.Add(vec); //} NearestNeighbor.NearestNeighbor interpolation = new NearestNeighbor.NearestNeighbor(); double[,] mappedPointsArray = new double[points.Count(), 3]; for (int i = 0; i < points.Count(); i++) { //if (vectorFielRegistratedPoints[i] != new Vector3d(0, 0, 0)) //{ mappedPointsArray.SetValue(points[i].X, i, 0); mappedPointsArray.SetValue(points[i].Y, i, 1); mappedPointsArray.SetValue(points[i].Z, i, 2); //} } double[,] _pointsOrig = new double[pointsOrig.Count(), 3]; for (int i = 0; i < _pointsOrig.GetLength(0); i++) { //if (vectorFielRegistratedPoints[i] != new Vector3d(0, 0, 0)) //{ _pointsOrig.SetValue(pointsOrig[i].X, i, 0); _pointsOrig.SetValue(pointsOrig[i].Y, i, 1); _pointsOrig.SetValue(pointsOrig[i].Z, i, 2); //} } MWCellArray outInterpolatedArray = null; Console.WriteLine("Start of nearest point interpolation algorithm"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // Interpolate between outNewPointsMono and map_pointsStereo // finds the nearest neighbor in _pointsOrig for each point in mappedPointsArray. outInterpolatedArray is a column vector with my rows. // Each row in outInterpolatedArray contains the index of nearest neighbor in _pointsOrig for the corresponding row in mappedPointsArray. outInterpolatedArray = (MWCellArray)interpolation.getnearestPosition((MWNumericArray)_pointsOrig, (MWNumericArray)mappedPointsArray); stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; Console.WriteLine("End of NNInterpolation algorithm, it took : {0} minuts and {1} seconds!", ts.Minutes, ts.Seconds); MWNumericArray outInterpolatedNumericArray = (MWNumericArray)outInterpolatedArray[1]; List <int> l_interpolatedPoints = new List <int>(); List <Vector3d> interpolatedMappedPoints = new List <Vector3d>(); for (int i = 1; i < outInterpolatedNumericArray.Dimensions[0] + 1; i++) { int interpolatedPoint = (int)outInterpolatedNumericArray[i, 1]; l_interpolatedPoints.Add(interpolatedPoint); } return(l_interpolatedPoints); }
public FrequencyInfo realtimeAnalyze() { /* * MWCellArray EPCArray = new MWCellArray(tagInfoQueue.Count, 1); * * int count = 0; * ulong[] timestamp = new ulong[tagInfoQueue.Count]; * ushort[] phase = new ushort[tagInfoQueue.Count]; * int[] frequency = new int[tagInfoQueue.Count]; * foreach(TagInfo tagInfo in tagInfoQueue) * { * timestamp[count] = tagInfo.TimeStamp; * phase[count] = tagInfo.RawPhase; * frequency[count] = tagInfo.Frequency; * EPCArray[++count, 1] = tagInfo.EPC; * } * MWNumericArray timeStampArray = timestamp; * MWNumericArray phaseArray = phase; * MWNumericArray frequencyIndex = frequency; * MWArray[] argsIn = new MWArray[] { EPCArray, timeStampArray, phaseArray, frequencyIndex,0,1,10 }; * MWArray[] result = new MWArray[3]; * VitalSignsExtract vitalSignsExtract = new VitalSignsExtract(); * vitalSignsExtract.vitalSignsExtract(3,ref result,argsIn); */ Console.WriteLine("Realtime Analyzing..."); long[] timestampArray = timestampQueue.ToArray(); MWNumericArray timeStampArray = timestampArray; double[] phaseArray1 = phaseQueue.ToArray(); MWNumericArray phaseArray = phaseArray1; int[] frequencyArray = frequencyQueue.ToArray(); MWNumericArray frequencyIndex = frequencyArray; string[] epcArray = epcQueue.ToArray(); Console.WriteLine("array size : " + epcArray.Length); MWCellArray EPCArray = new MWCellArray(epcArray.Length, 1); //MWNumericArray filter = 0; //MWNumericArray method = 1; //MWNumericArray T = 10; for (int i = 0; i < epcArray.Length; i++) { EPCArray[i + 1, 1] = epcArray[i]; } MWArray[] argsIn = new MWArray[] { EPCArray, timeStampArray, phaseArray, frequencyIndex, 0, 1, 10 }; MWArray[] result = new MWArray[3]; FrequencyInfo fre = new FrequencyInfo(); try { vitalSignsExtract.vitalSignsExtract(3, ref result, argsIn); double[,] breathAndHb = (double[, ])(result[0].ToArray()); int fail = (int)(MWNumericArray)result[2]; Console.WriteLine("fail: " + fail); fre.meanBreath = breathAndHb[0, 1]; fre.meanHeartbeat = breathAndHb[0, 3]; Console.WriteLine("breath:" + breathAndHb[0, 1] + " " + breathAndHb[0, 2]); Console.WriteLine("heartbeat:" + fre.meanHeartbeat + " " + breathAndHb[0, 4]); fre.fail = fail; }catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } return(fre); }
public void IdentifyComputation() { //set generic simulator behavior - strategy //GenericSimulator.SimulatorBehavior = new MySincSimulatorBehavior2(); //useless - matlab DLL have different static instance try { BroadcastIdentifyStateMessage("Starting calculation ..." + DateTime.Now); logger.Log(NLog.LogLevel.Info, "starting calculation "); //invoke matlab Identification algorithm - does it use the GenericSimulator instance configured before??? Class1 class1 = new Class1(); logger.Log(NLog.LogLevel.Debug, "class1 init"); //set experiment variables and values MWArray v_names = new MWCellArray(new MWCharArray(Enumerable.ToArray(variable_names))); MWArray experiment = new MWNumericArray(variable_values); //set identification parameters MWArray p_names = new MWCellArray(new MWCharArray(Enumerable.ToArray(parameters.Keys))); //set worker nodes urls //var host = AppHostBase.Instance.Config.ServiceEndpointsMetadataConfig.DefaultMetadataUri; //var myrepository = ((AppHostBase) EndpointHost.AppHost).Container.Resolve<WorkersRepository>(); //MWArray worker_urls = new MWCellArray(new MWCharArray(myrepository.GetByModelName(modelname).Select(x => x.RestUrl).ToArray())); MWArray p_val = new MWNumericArray(parameters.Values.Select(parameter => parameter.Value).ToArray()); MWArray p_min = new MWNumericArray(parameters.Values.Select(parameter => parameter.Min).ToArray()); MWArray p_max = new MWNumericArray(parameters.Values.Select(parameter => parameter.Max).ToArray()); MWArray p_is_fixed = new MWLogicalArray(parameters.Values.Select(parameter => !parameter.IsActive).ToArray()); //calculate identification Stopwatch sw = Stopwatch.StartNew(); if (IAgenerations > 0) //set gaoptions { MWArray generations = new MWNumericArray(IAgenerations); MWArray populationsize = new MWNumericArray(IApopulationsize); MWArray tolfun = new MWNumericArray(IAtolfun); class1.identify_gaoptimset(generations, populationsize, tolfun); } //otherwise the matlab algorithm has it's own default values logger.Log(NLog.LogLevel.Debug, "mwarray init"); var result = class1.identify_main(experiment, p_names, p_val, p_min, p_max, p_is_fixed, v_names, modelname, masterserviceurl); logger.Log(NLog.LogLevel.Debug, "identify_main done"); sw.Stop(); /*var fitted_params = result[1]; var fitted_param_L2Enorm = result[2]; var fitted_variablevalues = result[3]; * */ //string fittedparams = ""; //for (int i=1;i < fitted_params. //BroadcastIdentifyStateMessage("Elapsed time " + sw.Elapsed.ToString() + " Results: " + result);//fitted_params+" "+fitted_param_L2Enorm+" " + fitted_variablevalues); //var myresult = result.ToArray(); BroadcastIdentifyResult(result.ToArray(),sw.Elapsed,class1.identify_getssq(),class1.identify_getcomputationcycles(),class1.identify_getsimulationtime()); } catch (Exception e) { //TODO handle matlab exception BroadcastIdentifyStateMessage(e.Message+e.StackTrace); logger.Log(NLog.LogLevel.Error,"exception during identification "+e.Message+" stacktrace:"+e.StackTrace,e); var f = e;//.InnerException; while (f.InnerException != null) { f = f.InnerException; logger.Log(NLog.LogLevel.Error, "innerexception:" + f.Message + " stacktrace:" + f.StackTrace, f); } } // StopIdentify(); FinalizeIdentify(); }
void PlotAll() { /* 不同年 同月的数据*/ int length = band.ToArray().Length; MWNumericArray band_1 = new MWNumericArray(MWArrayComplexity.Real, length, 1); MWNumericArray band_2 = new MWNumericArray(MWArrayComplexity.Real, length, 1); MWNumericArray band_3 = new MWNumericArray(MWArrayComplexity.Real, length, 1); MWNumericArray band_4 = new MWNumericArray(MWArrayComplexity.Real, length, 1); MWCellArray time_1 = new MWCellArray(4); string this_time = cover.time; DateTime this_date = Convert.ToDateTime(this_time + "-28"); string last1_time; string last2_time; string last3_time; if (Convert.ToDouble(this_date.Month) >= 10) { last1_time = this_date.AddYears(-1).Year.ToString() + "-" + this_date.Month.ToString(); last2_time = this_date.AddYears(-2).Year.ToString() + "-" + this_date.Month.ToString(); last3_time = this_date.AddYears(-3).Year.ToString() + "-" + this_date.Month.ToString(); } else { last1_time = this_date.AddYears(-1).Year.ToString() + "-0" + this_date.Month.ToString(); last2_time = this_date.AddYears(-2).Year.ToString() + "-0" + this_date.Month.ToString(); last3_time = this_date.AddYears(-3).Year.ToString() + "-0" + this_date.Month.ToString(); } //MessageBox.Show(last1_time + last2_time + last3_time); band_2 = DataGet(last1_time); band_3 = DataGet(last2_time); band_4 = DataGet(last3_time); for (int i = 0; i < length; i++) { band_1[i + 1] = band[i]; } time_1[1] = this_time; time_1[2] = last1_time; time_1[3] = last2_time; time_1[4] = last3_time; /* 同年不同月 的数据*/ MWNumericArray band_5 = new MWNumericArray(MWArrayComplexity.Real, length, 1); MWNumericArray band_6 = new MWNumericArray(MWArrayComplexity.Real, length, 1); MWNumericArray band_7 = new MWNumericArray(MWArrayComplexity.Real, length, 1); MWCellArray time_2 = new MWCellArray(4); if (Convert.ToDouble(this_date.AddMonths(-1).Month) >= 10) { last1_time = this_date.AddMonths(-1).Year.ToString() + "-" + this_date.AddMonths(-1).Month.ToString(); } else { last1_time = this_date.AddMonths(-1).Year.ToString() + "-0" + this_date.AddMonths(-1).Month.ToString(); } if (Convert.ToDouble(this_date.AddMonths(-2).Month) >= 10) { last2_time = this_date.AddMonths(-2).Year.ToString() + "-" + this_date.AddMonths(-2).Month.ToString(); } else { last2_time = this_date.AddMonths(-2).Year.ToString() + "-0" + this_date.AddMonths(-2).Month.ToString(); } if (Convert.ToDouble(this_date.AddMonths(-3).Month) >= 10) { last3_time = this_date.AddMonths(-3).Year.ToString() + "-" + this_date.AddMonths(-3).Month.ToString(); } else { last3_time = this_date.AddMonths(-3).Year.ToString() + "-0" + this_date.AddMonths(-3).Month.ToString(); } //MessageBox.Show(last1_time + last2_time + last3_time); band_5 = DataGet(last1_time); band_6 = DataGet(last2_time); band_7 = DataGet(last3_time); for (int i = 0; i < length; i++) { band_1[i + 1] = band[i]; } time_2[1] = this_time; time_2[2] = last1_time; time_2[3] = last2_time; time_2[4] = last3_time; plot_all.grid_all(cover.lon_max, cover.lon_min, cover.lat_max, cover.lat_min, band_1, band_2, band_3, band_4, band_5, band_6, band_7, 1, time_1, time_2); }