public string Export(Model model, bool compressed = false) { ModelJSON mdJson = new ModelJSON(); model.Relabel(false); if (model.Molecules.Count == 1) { Molecule m1 = model.Molecules.Values.First(); var mj = ExportMol(m1); return(WriteJson(mj, compressed)); } else if (model.Molecules.Count > 1) { mdJson.m = new MolJSON[model.Molecules.Count]; int i = 0; foreach (Molecule mol in model.Molecules.Values) { var mj = ExportMol(mol); mdJson.m[i] = mj; i++; } } return(WriteJson(mdJson, compressed)); }
public string Export(Model model) { ModelJSON mdJson = new ModelJSON(); model.Relabel(); if (model.Molecules.Count == 1) { Molecule m1 = model.Molecules[0]; var mj = ExportMol(m1); return(JsonConvert.SerializeObject(mj, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore })); } else if (model.Molecules.Count > 1) { mdJson.m = new MolJSON[model.Molecules.Count]; int i = 0; foreach (Molecule mol in model.Molecules) { var mj = ExportMol(mol); mdJson.m[i] = mj; i++; } } return(JsonConvert.SerializeObject(mdJson, Formatting.Indented, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore })); }
public static ModelJSON Convert(Model model) { var json = new ModelJSON { ModelX = new double[model.ModelX.y, model.ModelX.x], ModelY = new double[model.ModelY.Length()], Type = (int)model.Type, KernelParam = new double[model.KernelParam.Length()], Alpha = new double[model.Alpha.Length()], W = new double[model.W.Length()], B = model.B, C = model.C, Tolerance = model.Tolerance, Category = model.Category, Passes = model.Passes, Iterations = model.Iterations, MaxIterations = model.MaxIterations, Trained = model.Trained }; for (var j = 0; j < model.ModelX.y; j++) { for (var i = 0; i < model.ModelX.x; i++) { json.ModelX[j, i] = model.ModelX[i, j]; } } for (var j = 0; j < model.ModelY.Length(); j++) { json.ModelY[j] = model.ModelY[j]; } for (var j = 0; j < model.KernelParam.Length(); j++) { json.KernelParam[j] = model.KernelParam[j]; } for (var j = 0; j < model.W.Length(); j++) { json.W[j] = model.W[j]; } for (var j = 0; j < model.Alpha.Length(); j++) { json.Alpha[j] = model.Alpha[j]; } return(json); }