/// <summary> /// Выполнение итерационного алгоритма для текущего графа Graph /// </summary> public void PerformAlgorithm() { //Начальная инициализация множеств var AllVariables = GetVariables(); for (int i = 0; i < Graph.blocks.Count; i++) { IN.Add(new Dictionary <string, string>(AllVariables)); OUT.Add(new Dictionary <string, string>(AllVariables)); } // Сам итерационный алгоритм bool isChanged = true; while (isChanged) { isChanged = false; for (int i = 1; i < Graph.blocks.Count; i++) { var prevOUT = new Dictionary <string, string>(OUT[i]); IN[i] = MeetOperator(i); OUT[i] = Function(IN[i], Graph.blocks[i]); isChanged = isChanged || IsDictionariesEquals(prevOUT, OUT[i]); } } }
private double Percentage(OUT key, ClassicCounter <OUT> guessed, ClassicCounter <OUT> guessedCorrect) { double thisGuessed = guessed.GetCount(key); double thisGuessedCorrect = guessedCorrect.GetCount(key); return((thisGuessed == 0.0) ? 0.0 : thisGuessedCorrect / thisGuessed); }
protected internal Arc(NODE sourceNode, NODE targetNode, IN input, OUT output) { // makes a copy of Arc a this.sourceNode = sourceNode; this.targetNode = targetNode; this.input = input; this.output = output; }
public override void Serialize(BinaryWriter writer) { writer.Write(Name); writer.Write(Delay); writer.Write(X); writer.Write(Y); writer.Write((int)Direction); IN.Serialize(writer); OUT.Serialize(writer); }
public override void Serialize(BinaryWriter writer) { writer.Write(GateType); writer.Write(Name); writer.Write(NameRoot); writer.Write(X); writer.Write(Y); writer.Write((int)Direction); IN_1.Serialize(writer); IN_2.Serialize(writer); OUT.Serialize(writer); }
public override int GetHashCode() { var hashCode = 436951639; hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Name); hashCode = hashCode * -1521134295 + Begin_Balance.GetHashCode(); hashCode = hashCode * -1521134295 + IN.GetHashCode(); hashCode = hashCode * -1521134295 + OUT.GetHashCode(); hashCode = hashCode * -1521134295 + Final_Balance.GetHashCode(); hashCode = hashCode * -1521134295 + Total_Value.GetHashCode(); return(hashCode); }
//Outputs schalten public bool SwitchOut(OUT GPIO_Pin, bool Closed) { GPIOMem Output; switch (GPIO_Pin) { case OUT.GPIO17: Output = out_gpio17; break; default: return(false); } Output.Write(Closed); return(true); }
public void TestOUT() { SignalBus signals = new SignalBus(); Operation op = new OUT(null, signals, null); signals.Reset(); op.Step0(); Assert.IsTrue(signals.MI); Assert.IsTrue(signals.CO); signals.Reset(); op.Step1(); Assert.IsTrue(signals.RO); Assert.IsTrue(signals.II); Assert.IsTrue(signals.CE); signals.Reset(); op.Step2(); Assert.IsTrue(signals.AO); Assert.IsTrue(signals.OI); }
internal virtual Pair <ClassicCounter <OUT>, ClassicCounter <OUT> > EvalPrecision(ICollection <In> guesses, ICollection <In> golds) { ICollection <In> internalGuesses = null; ICollection <In> internalGolds = null; if (bagEval) { internalGuesses = new List <In>(guesses.Count); internalGolds = new List <In>(golds.Count); } else { internalGuesses = Generics.NewHashSet(guesses.Count); internalGolds = Generics.NewHashSet(golds.Count); } Sharpen.Collections.AddAll(internalGuesses, guesses); Sharpen.Collections.AddAll(internalGolds, golds); ClassicCounter <OUT> thisGuessed = new ClassicCounter <OUT>(); ClassicCounter <OUT> thisCorrect = new ClassicCounter <OUT>(); foreach (IN o in internalGuesses) { OUT equivalenceClass = eq.EquivalenceClass(o); thisGuessed.IncrementCount(equivalenceClass); if (checker.Contained(o, internalGolds)) { thisCorrect.IncrementCount(equivalenceClass); RemoveItem(o, internalGolds, checker); } else { if (verbose) { System.Console.Out.WriteLine("Eval missed " + o); } } } return(Generics.NewPair(thisGuessed, thisCorrect)); }
public virtual double LastNumGuessed(OUT key) { return(previousGuessed.GetCount(key)); }
public virtual double LastRecall(OUT key) { return(Percentage(key, previousGold, previousGoldCorrect)); }
public virtual double LastPrecision(OUT key) { return(Percentage(key, previousGuessed, previousGuessedCorrect)); }
public virtual double Recall(OUT key) { return(Percentage(key, gold, goldCorrect)); }
public virtual double Precision(OUT key) { return(Percentage(key, guessed, guessedCorrect)); }
// Function for calculating Next Item public static NextItemModel NextItem_Calc(CATItems itemBank, string model = null, double theta = 0, int[] Out = null, int[] x = null, int criterion = 5, /* MFI */ string method = "BM", string priorDist = "norm", double[] priorPar = null, double D = 1, double[] range = null, int[] parInt = null, int infoType = 2, /* observed */ int randomesque = 1, int rule = 1, /* Length */ double thr = 20, double?SETH = null, double AP = 1, int[] nAvailable = null, int maxItems = 50, CBControlList cbControl = null, string[] cbGroup = null) { CATItems par = null; NextItemModel result = null; #region "Parameter Validation" if (priorPar == null || priorPar.Length < 2) { priorPar = new double[2]; priorPar[0] = 0; priorPar[1] = 1; } if (range == null || range.Length < 2) { range = new double[2]; range[0] = -4; range[1] = 4; } if (parInt == null || parInt.Length < 3) { parInt = new int[3]; parInt[0] = -4; parInt[1] = 4; parInt[2] = 33; } ModelNames.CriterionTypes?crit = null; switch (criterion) { case (int)ModelNames.CriterionTypes.bOpt: crit = ModelNames.CriterionTypes.bOpt; break; case (int)ModelNames.CriterionTypes.thOpt: crit = ModelNames.CriterionTypes.thOpt; break; case (int)ModelNames.CriterionTypes.KL: crit = ModelNames.CriterionTypes.KL; break; case (int)ModelNames.CriterionTypes.KLP: crit = ModelNames.CriterionTypes.KLP; break; case (int)ModelNames.CriterionTypes.MEI: crit = ModelNames.CriterionTypes.MEI; break; case (int)ModelNames.CriterionTypes.MEPV: crit = ModelNames.CriterionTypes.MEPV; break; case (int)ModelNames.CriterionTypes.MFI: crit = ModelNames.CriterionTypes.MFI; break; case (int)ModelNames.CriterionTypes.MLWI: crit = ModelNames.CriterionTypes.MLWI; break; case (int)ModelNames.CriterionTypes.MPWI: crit = ModelNames.CriterionTypes.MPWI; break; case (int)ModelNames.CriterionTypes.progressive: crit = ModelNames.CriterionTypes.progressive; break; case (int)ModelNames.CriterionTypes.proportional: crit = ModelNames.CriterionTypes.proportional; break; case (int)ModelNames.CriterionTypes.random: crit = ModelNames.CriterionTypes.random; break; } if (crit == null) { result = new NextItemModel(true, "Invalid 'criterion' name!"); return(result); } int mod = 0; ModelNames.Models modelEnum = ModelNames.StringToEnum(model); if (!String.IsNullOrEmpty(model)) { switch (modelEnum) { case ModelNames.Models.GRM: mod = 1; break; case ModelNames.Models.MGRM: mod = 2; break; case ModelNames.Models.PCM: mod = 3; break; case ModelNames.Models.GPCM: mod = 4; break; case ModelNames.Models.RSM: mod = 5; break; case ModelNames.Models.NRM: mod = 6; break; } if (mod == 0) { result = new NextItemModel(true, "Invalid 'model' type!"); return(result); } } #endregion int[] OUT = null; double[] empProp = null; int nrGroup = 0; double[] thProp = null; #region Handling "cbControl" Parameter if (cbControl == null) { OUT = Out; } else { if (cbGroup == null) { result = new NextItemModel(true, "'cbGroup' argument must be provided for content balancing!"); return(result); } if (RowColumn.Sum(cbControl.Props) != 1) { double temp_sum = RowColumn.Sum(cbControl.Props); for (int i = 0; i < cbControl.Props.Length; i++) { cbControl.Props[i] = cbControl.Props[i] / temp_sum; } } nrGroup = cbControl.Names.Length; empProp = new double[nrGroup]; if (Out == null) { empProp = CatRcs.Utils.CommonHelper.Replicate(new double[] { 0 }, nrGroup); } else { string[] temp_grp = new string[Out.Length]; for (int i = 0; i < Out.Length; i++) { temp_grp[i] = cbGroup[Out[i]]; } for (int j = 0; j < nrGroup; j++) { string[] values = temp_grp.Where(m => m == cbControl.Names[j]).ToArray(); if (values != null && values.Length > 0) { empProp[j] = values.Length; } else { empProp[j] = 0; } } empProp = empProp.Select(n => n / CatRcs.Utils.RowColumn.Sum(empProp)).ToArray(); // Functional Testing needed !! } thProp = cbControl.Props; List <int> indGroup = new List <int>(); int selGroup = 0; // Array of Group Numbers ex: "1 2 3 4 5" for nrGroup = 5. int[] GrpIndValues = new int[nrGroup]; GrpIndValues = GrpIndValues.Select((a, i) => i + 1).ToArray(); if (empProp.Min() == 0) { for (int m = 0; m < empProp.Length; m++) { if (empProp[m] == 0) { indGroup.Add(GrpIndValues[m]); } } } else { double[] tempProp = thProp.Select((a, i) => a - empProp[i]).ToArray(); for (int n = 0; n < tempProp.Length; n++) { if (tempProp[n] == tempProp.Max()) { indGroup.Add(GrpIndValues[n]); } } } if (indGroup.Count == 1) { selGroup = indGroup[0]; } else { selGroup = CatRcs.Utils.RandomNumberHandler.Sample(indGroup.ToArray(), 1, false)[0]; } // Populating the OUT array string[] tempGrp = cbGroup.Where(c => c != cbControl.Names[selGroup]).ToArray(); OUT = tempGrp.Select((a, i) => i + 1).ToArray(); OUT = Out.Concat(OUT).ToArray(); OUT = CatRcs.Utils.CommonHelper.Unique(OUT); } #endregion #region Handling "nAvalilable Parameter" if (nAvailable != null) { List <int> ind_temp = new List <int>(); for (int k = 0; k < nAvailable.Length; k++) { if (nAvailable[k] == 0) { ind_temp.Add(k); } } OUT = OUT.Concat(ind_temp.ToArray()).ToArray(); OUT = CatRcs.Utils.CommonHelper.Unique(OUT); } #endregion int select = 0; #region Criterion Type "MFI" if (crit == ModelNames.CriterionTypes.MFI) { int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] info = Ii.Ii_Calc(theta, itemBank, model, D).Ii; double[] ranks = CatRcs.Utils.CommonHelper.Rank(info).Select(m => m).ToArray(); int nrIt = new int[] { randomesque, (int)CatRcs.Utils.RowColumn.Sum(items) }.Min(); List <double> tempRanks = new List <double>(); for (int j = 0; j < items.Length; j++) { if (items[j] == 1) { tempRanks.Add(ranks[j]); } } tempRanks = tempRanks.OrderByDescending(n => n).ToList(); double[] keepRank = tempRanks.GetRange(0, nrIt).ToArray(); List <int> keep = new List <int>(); if (ranks.Length == items.Length) { for (int m = 0; m < keepRank.Length; m++) { for (int n = 0; n < ranks.Length; n++) { if ((items[n] == 1) && (ranks[n] == keepRank[m])) { keep.Add(n + 1); } } } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), info[select - 1], criterion, randomesque); } #endregion #region Criterion Type "bOpt" if (crit == ModelNames.CriterionTypes.bOpt) { if (string.IsNullOrEmpty(model)) { int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] distance = itemBank.GetItemParamter(CATItems.ColumnNames.b).Select(a => Math.Abs(a - theta)).ToArray(); double[] ranks = CatRcs.Utils.CommonHelper.Rank(distance).Select(m => m).ToArray(); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { ranks[OUT[a] - 1] = -1; } } int nrIt = new int[] { randomesque, (int)CatRcs.Utils.RowColumn.Sum(items) }.Min(); List <double> tempRanks = new List <double>(); for (int j = 0; j < items.Length; j++) { if (items[j] == 1) { tempRanks.Add(ranks[j]); } } tempRanks = tempRanks.OrderBy(n => n).ToList(); double[] keepRank = tempRanks.GetRange(0, nrIt).ToArray(); keepRank = keepRank.Distinct().ToArray(); List <int> keep = new List <int>(); if (ranks.Length == items.Length) { for (int m = 0; m < keepRank.Length; m++) { for (int n = 0; n < ranks.Length; n++) { if ((items[n] == 1) && (ranks[n] == keepRank[m])) { keep.Add(n + 1); } } } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), distance[select - 1], criterion, randomesque); } else { result = new NextItemModel(true, "bOpt's rule cannot be considered with polytomous items!"); return(result); } } #endregion #region Criterion Type "MLWI" OR "MPWI" if (crit == ModelNames.CriterionTypes.MLWI || crit == ModelNames.CriterionTypes.MPWI) { if (Out != null) { if (Out.Length == 1) { par = itemBank.FindItem(Out[0]); } else { par = itemBank.FindItem(Out); } } else { result = new NextItemModel(true, "Out parameter can't be empty!"); return(result); } int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] likInfo = CatRcs.Utils.CommonHelper.Replicate(new double[] { 0 }, itemBank.NumOfItems); int mwiType = 0; if (criterion == (int)ModelNames.CriterionTypes.MLWI) { mwiType = (int)ModelNames.MWI_Type.MLWI; } if (criterion == (int)ModelNames.CriterionTypes.MPWI) { mwiType = (int)ModelNames.MWI_Type.MPWI; } if (x != null) { for (int j = 0; j < itemBank.NumOfItems; j++) { if (items[j] == 1) { likInfo[j] = MWI.MWI_Calc(itemBank, j + 1, x, par, model, mwiType, priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]); /* item number is always 1 greater than the index */ } } } int nrIt = new int[] { randomesque, (int)CatRcs.Utils.RowColumn.Sum(items) }.Min(); double likVal = likInfo.ToList().OrderByDescending(n => n).ToArray()[nrIt - 1]; // First value with index 0 List <int> keep = new List <int>(); for (int k = 0; k < items.Length; k++) { if (likInfo[k] >= likVal) { keep.Add(k + 1); // Converting from index to item number } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), likInfo[select - 1], criterion, randomesque); } #endregion #region Criterion Type "KL" OR "KLP" if (crit == ModelNames.CriterionTypes.KL || crit == ModelNames.CriterionTypes.KLP) { if (Out != null) { if (Out.Length == 1) { par = itemBank.FindItem(Out[0]); } else { par = itemBank.FindItem(Out); } } else { result = new NextItemModel(true, "Out parameter can't be empty!"); return(result); } int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] klValue = CatRcs.Utils.CommonHelper.Replicate(new double[] { 0 }, itemBank.NumOfItems); double[] X = CatRcs.Utils.CommonHelper.Sequence(parInt[0], parInt[1], parInt[2]); #region "Function 'L' " Func <double, int[], CATItems, double> L = (th, r, param) => { double res = 0; var temp_1 = Pi.Pi_Calc(th, param, model, D).Pi.Select((p, i) => Math.Pow(p, r[i])).ToArray(); var temp_2 = Pi.Pi_Calc(th, param, model, D).Pi.Select((p, i) => Math.Pow(1 - p, 1 - r[i])).ToArray(); if (temp_1.Length == temp_2.Length) { var temp_3 = temp_1.Select((p, i) => p * temp_2[i]).ToArray(); res = temp_3.Aggregate((acc, val) => acc * val); } return(res); }; #endregion #region "Function 'LL' " Func <double, int[], CATItems, double> LL = (th, r, param) => { double res = 0; if (param.NumOfItems == 0) { res = 1; } else { double[,] prob = Pi.Pi_Poly_Calc(th, param, model, D).Pi; for (int i = 0; i < r.Length; i++) { res = res * prob[i, r[i] + 1]; } } return(res); }; #endregion double[] LF = null; if (string.IsNullOrEmpty(model)) { LF = X.Select(p => L(p, x, par)).ToArray(); } else { LF = X.Select(p => LL(p, x, par)).ToArray(); } int kType = 0; if (criterion == (int)ModelNames.CriterionTypes.KL) { kType = (int)ModelNames.KLTypes.KL; } if (criterion == (int)ModelNames.CriterionTypes.KLP) { kType = (int)ModelNames.KLTypes.KLP; } for (int j = 0; j < itemBank.NumOfItems; j++) { if (items[j] == 1) { klValue[j] = KL.KL_Calc(itemBank, j + 1, x, par, model, theta, priorPar, X, LF, kType, D, priorDist, parInt[0], parInt[1], parInt[2]); /* item number is always 1 greater than the index */ } } int nrIt = new int[] { randomesque, (int)CatRcs.Utils.RowColumn.Sum(items) }.Min(); double klVal = klValue.ToList().OrderByDescending(n => n).ToArray()[nrIt - 1]; List <int> keep = new List <int>(); for (int k = 0; k < items.Length; k++) { if (klValue[k] >= klVal) { keep.Add(k + 1); } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), klValue[select - 1], criterion, randomesque); } #endregion #region Criterion Type "MEI" if (crit == ModelNames.CriterionTypes.MEI) { int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] infos = CatRcs.Utils.CommonHelper.Replicate(new double[] { 0 }, itemBank.NumOfItems); for (int j = 0; j < items.Length; j++) { if (items[j] > 0) { infos[j] = MEI.MEI_Calc(itemBank, j + 1, x, theta, itemBank.FindItem(Out), model, method, D, priorPar, priorDist, range, parInt, infoType); } } int nrIt = new int[] { randomesque, (int)CatRcs.Utils.RowColumn.Sum(items) }.Min(); double infoVal = infos.ToList().OrderByDescending(n => n).ToArray()[nrIt - 1]; List <int> keep = new List <int>(); for (int k = 0; k < items.Length; k++) { if (infos[k] >= infoVal) { keep.Add(k + 1); } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), infos[select - 1], criterion, randomesque); } #endregion #region Criterion Type "MEPV" if (crit == ModelNames.CriterionTypes.MEPV) { int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] epvs = CatRcs.Utils.CommonHelper.Replicate(new double[] { 1000 }, itemBank.NumOfItems); for (int j = 0; j < items.Length; j++) { if (items[j] > 0) { epvs[j] = EPV.EPV_Calc(itemBank, j + 1, x, theta, itemBank.FindItem(Out), model, priorPar, parInt, D, priorDist); } } var tempVal = new int[] { randomesque, items.Sum() }.Min(); double epVal = epvs.ToList().OrderBy(n => n).ToArray()[tempVal - 1]; List <int> keep = new List <int>(); for (int k = 0; k < itemBank.NumOfItems; k++) { if (epvs[k] <= epVal) { keep.Add(k + 1); } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), epvs[select - 1], criterion, randomesque); } #endregion #region Criterion Type "random" if (crit == ModelNames.CriterionTypes.random) { int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a]] = 0; } } int gen = Convert.ToInt32(Convert.ToInt32(CatRcs.Utils.RandomNumberHandler.Runif(1, 0, 1)[0]) * items.Sum()) + 1; List <int> indexs = new List <int>(); for (int k = 0; k < itemBank.NumOfItems; k++) { if (items[k] > 0) { indexs.Add(k + 1); } } select = indexs.ElementAt(gen); result = new NextItemModel(select, itemBank.FindItem(select), double.NaN, criterion, randomesque); } #endregion #region Criterion Type "progressive" if (crit == ModelNames.CriterionTypes.progressive) { int item_administered = Out.Length; int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] info = Ii.Ii_Calc(theta, itemBank, model, D).Ii; List <double> tempItems = new List <double>(); for (int j = 0; j < items.Length; j++) { if (items[j] == 1) { tempItems.Add(info[j]); } } double wq = 0; double itemMaxInfo = tempItems.Max(); double[] randomValues = CatRcs.Utils.RandomNumberHandler.Runif(items.Length, 0, itemMaxInfo); if (rule == (int)ModelNames.RuleType.Precision) { double infostop = Math.Pow((1 / thr), 2); double cuminfo = Math.Pow(double.Parse((1 / SETH).ToString()), 2); if (item_administered > 0) { wq = Math.Pow(new double[] { cuminfo / infostop, item_administered / (maxItems - 1) }.Max(), AP); } } if (rule == (int)ModelNames.RuleType.Length) { if (item_administered > 0) { List <double> tempNum = new List <double>(); for (int i = 1; i <= item_administered; i++) { tempNum.Add(Math.Pow(i, AP)); } double numerador = tempNum.Sum(); List <double> tempDenom = new List <double>(); for (int j = 1; j <= thr - 1; j++) { tempDenom.Add(Math.Pow(j, AP)); } double denominador = tempDenom.Sum(); wq = numerador / denominador; } } double[] funcPR = info.Select((d, i) => d * wq + randomValues[i] * (1 - wq)).ToArray(); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { funcPR[OUT[a] - 1] = 0; } } List <int> keep = new List <int>(); for (int k = 0; k < funcPR.Length; k++) { if (funcPR[k] == funcPR.Max()) { keep.Add(k + 1); } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), info[select - 1], criterion, randomesque); } #endregion #region Criterion Type "proportional" if (crit == ModelNames.CriterionTypes.proportional) { int item_administered = Out.Length; int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double wq = 0; if (rule == (int)ModelNames.RuleType.Precision) { double infostop = Math.Pow((1 / thr), 2); double cuminfo = Math.Pow(double.Parse((1 / SETH).ToString()), 2); if (item_administered > 0) { wq = infostop * Math.Pow(new double[] { cuminfo / infostop, item_administered / (maxItems - 1) }.Max(), AP); } } if (rule == (int)ModelNames.RuleType.Length) { if (item_administered > 0) { List <double> tempNum = new List <double>(); for (int i = 1; i <= item_administered; i++) { tempNum.Add(Math.Pow(i, AP)); } double numerador = tempNum.Sum(); List <double> tempDenom = new List <double>(); for (int j = 1; j <= thr - 1; j++) { tempDenom.Add(Math.Pow(j, AP)); } double denominador = tempDenom.Sum(); wq = thr * numerador / denominador; } } double[] info = Ii.Ii_Calc(theta, itemBank, model, D).Ii; double[] infoPR = info.Select(s => Math.Pow(s, wq)).ToArray(); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { infoPR[OUT[a] - 1] = 0; } } List <double> tempInfoPR = new List <double>(); for (int k = 0; k < items.Length; k++) { if (items[k] == 1) { tempInfoPR.Add(infoPR[k]); } } double totalInfoPR = tempInfoPR.Sum(); double[] probSelect = infoPR.Select(m => m / totalInfoPR).ToArray(); int[] selectItems = items.Select((n, i) => i + 1).ToArray(); select = CatRcs.Utils.RandomNumberHandler.Sample(selectItems, 1, false)[0]; // prob parameter will be added after Sample functiom modification result = new NextItemModel(select, itemBank.FindItem(select), info[select], criterion, randomesque); } #endregion #region Criterion Type "thOpt" if (crit == ModelNames.CriterionTypes.thOpt) { if (string.IsNullOrEmpty(model)) // Only for Dichotomous Items { int[] items = CatRcs.Utils.CommonHelper.Replicate(new int[] { 1 }, itemBank.NumOfItems); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { items[OUT[a] - 1] = 0; } } double[] u = itemBank.GetItemParamter(CATItems.ColumnNames.c).Select((s, i) => - 0.75 + (s + itemBank.GetItemParamter(CATItems.ColumnNames.d)[i] + -2 * s * itemBank.GetItemParamter(CATItems.ColumnNames.d)[i]) / 2).ToArray(); double[] v = itemBank.GetItemParamter(CATItems.ColumnNames.c).Select((n, i) => (n + itemBank.GetItemParamter(CATItems.ColumnNames.d)[i] - 1) / 4).ToArray(); double[] xstar = u.Select((m, i) => 2 * Math.Sqrt(-m / 3) * Math.Cos(Math.Acos(-v[i] * Math.Sqrt(-27 / Math.Pow(m, 3)) / 2) / 3 + 4 * (Math.PI / 3)) + 0.5).ToArray(); double[] thstar = itemBank.GetItemParamter(CATItems.ColumnNames.b).Select((o, i) => o + Math.Log((xstar[i] - itemBank.GetItemParamter(CATItems.ColumnNames.c)[i]) / (itemBank.GetItemParamter(CATItems.ColumnNames.d)[i] - xstar[i])) / (D * itemBank.GetItemParamter(CATItems.ColumnNames.a)[i])).ToArray(); double[] distance = thstar.Select(p => Math.Abs(p - theta)).ToArray(); double[] ranks = CatRcs.Utils.CommonHelper.Rank(distance).Select(m => m).ToArray(); if (OUT != null) { for (int a = 0; a < OUT.Length; a++) { ranks[OUT[a] - 1] = -1; } } int nrIt = new int[] { randomesque, (int)CatRcs.Utils.RowColumn.Sum(items) }.Min(); List <double> tempRanks = new List <double>(); for (int j = 0; j < items.Length; j++) { if (items[j] == 1) { tempRanks.Add(ranks[j]); } } tempRanks = tempRanks.OrderBy(n => n).ToList(); double[] keepRank = tempRanks.GetRange(0, nrIt).ToArray(); keepRank = keepRank.Distinct().ToArray(); List <int> keep = new List <int>(); if (ranks.Length == items.Length) { for (int m = 0; m < keepRank.Length; m++) { for (int n = 0; n < ranks.Length; n++) { if ((items[n] == 1) && (ranks[n] == keepRank[m])) { keep.Add(n + 1); } } } } if (keep.Count == 1) { select = keep[0]; } else { select = CatRcs.Utils.RandomNumberHandler.Sample(keep.ToArray(), 1, false)[0]; } result = new NextItemModel(select, itemBank.FindItem(select), distance[select - 1], criterion, randomesque); } else { result = new NextItemModel(true, "thOpt's rule cannot be considered with polytomous items!"); return(result); } } #endregion #region Handling "cbControl" Parameter if (cbControl == null) { if (result != null) { result.prior_prop = null; result.post_prop = null; result.cb_prop = null; } } else { result.prior_prop = empProp; double[] postProp = new double[nrGroup]; string[] temp_grp = new string[Out.Length + 1]; for (int i = 0; i < temp_grp.Length; i++) { if (i == 0) { temp_grp[i] = cbGroup[result.item]; } temp_grp[i] = cbGroup[Out[i]]; } for (int j = 0; j < postProp.Length; j++) { string[] values = temp_grp.Where(m => m == cbControl.Names[j]).ToArray(); if (values != null && values.Length > 0) { postProp[j] = values.Length; } else { postProp[j] = 0; } } result.post_prop = postProp.Select(n => n / CatRcs.Utils.RowColumn.Sum(postProp)).ToArray(); result.cb_prop = thProp; } #endregion return(result); }
public virtual double LastF1(OUT key) { return(F1(LastPrecision(key), LastRecall(key))); }
public virtual double LastNumGolds(OUT key) { return(previousGold.GetCount(key)); }
public virtual void SetOutput(OUT o) { output = o; }
virtual HRESULT GetHttpModule( OUT CHttpModule **ppModule,
//**************************************************************************** //メソッド名:OutBit(指定ポートにビット単位での出力) //引数:引数�@ ポート名("P00"、"P01"・・・"P07")引数�A出力値(H:0/ L: 1) //戻り値:正常0、異常1 //**************************************************************************** public int OutBit(PORT pName, BIT bName, OUT data) { //ポートの特定 byte PortOutData = 0; switch (pName) { case PORT.P0: this.Port = EPX64R_PORT0; PortOutData = this.p0Outdata; break; case PORT.P1: this.Port = EPX64R_PORT1; PortOutData = this.p1Outdata; break; case PORT.P2: this.Port = EPX64R_PORT2; PortOutData = this.p2Outdata; break; case PORT.P3: this.Port = EPX64R_PORT3; PortOutData = this.p3Outdata; break; case PORT.P4: this.Port = EPX64R_PORT4; PortOutData = this.p4Outdata; break; case PORT.P5: this.Port = EPX64R_PORT5; PortOutData = this.p5Outdata; break; case PORT.P6: this.Port = EPX64R_PORT6; PortOutData = this.p6Outdata; break; case PORT.P7: this.Port = EPX64R_PORT7; PortOutData = this.p7Outdata; break; default: return(1); } //ビットの特定 byte Temp = 0; int Num = 0; switch (bName) { case BIT.b0: Num = 0; Temp = 0xFE; break; case BIT.b1: Num = 1; Temp = 0xFD; break; case BIT.b2: Num = 2; Temp = 0xFB; break; case BIT.b3: Num = 3; Temp = 0xF7; break; case BIT.b4: Num = 4; Temp = 0xEF; break; case BIT.b5: Num = 5; Temp = 0xDF; break; case BIT.b6: Num = 6; Temp = 0xBF; break; case BIT.b7: Num = 7; Temp = 0x7F; break; } //データの出力 byte Data = 0; switch (data) { case OUT.H: Data = 1; break; case OUT.L: Data = 0; break; } byte OutputValue = (byte)((PortOutData & Temp) | (Data << Num));//byteでキャストしないと怒られる int flag = EPX64R.EPX64R_OutputPort(this.hDevice, Port, OutputValue); if (flag != EPX64R.EPX64R_OK) { EPX64R.EPX64R_Close(this.hDevice); // Device Close //MessageBox.Show("EPX64R_OutputPort() Error"); return(1); } switch (pName) { case PORT.P0: this.p0Outdata = OutputValue; break; case PORT.P1: this.p1Outdata = OutputValue; break; case PORT.P2: this.p2Outdata = OutputValue; break; case PORT.P3: this.p3Outdata = OutputValue; break; case PORT.P4: this.p4Outdata = OutputValue; break; case PORT.P5: this.p5Outdata = OutputValue; break; case PORT.P6: this.p6Outdata = OutputValue; break; case PORT.P7: this.p7Outdata = OutputValue; break; } return(0); }
//Outputs schalten public bool SwitchOut(OUT GPIO_Pin, bool Closed) { GPIOMem Output; switch (GPIO_Pin) { case OUT.GPIO17: Output = out_gpio17; break; default: return false; } Output.Write(Closed); return true; }
public virtual double F1(OUT key) { return(F1(Precision(key), Recall(key))); }
//**************************************************************************** //メソッド名:OutBit(指定ポートにビット単位での出力) //引数:引数�@ ポート名("P00"、"P01"・・・"P07")引数�A出力値(H:0/ L: 1) //戻り値:bool //**************************************************************************** public bool OutBit(PORT pName, BIT bName, OUT data) { byte buffOutData = 0; //現時点で出力しているデータ try { //ポートの特定 switch (pName) { case PORT.P0: this.Port = EPX64S_PORT0; buffOutData = this.p0Outdata; break; case PORT.P1: this.Port = EPX64S_PORT1; buffOutData = this.p1Outdata; break; case PORT.P2: this.Port = EPX64S_PORT2; buffOutData = this.p2Outdata; break; case PORT.P3: this.Port = EPX64S_PORT3; buffOutData = this.p3Outdata; break; case PORT.P4: this.Port = EPX64S_PORT4; buffOutData = this.p4Outdata; break; case PORT.P5: this.Port = EPX64S_PORT5; buffOutData = this.p5Outdata; break; case PORT.P6: this.Port = EPX64S_PORT6; buffOutData = this.p6Outdata; break; case PORT.P7: this.Port = EPX64S_PORT7; buffOutData = this.p7Outdata; break; default: break; } //ビットの特定 byte Temp = 0; int Num = 0; switch (bName) { case BIT.b0: Num = 0; Temp = 0xFE; break; case BIT.b1: Num = 1; Temp = 0xFD; break; case BIT.b2: Num = 2; Temp = 0xFB; break; case BIT.b3: Num = 3; Temp = 0xF7; break; case BIT.b4: Num = 4; Temp = 0xEF; break; case BIT.b5: Num = 5; Temp = 0xDF; break; case BIT.b6: Num = 6; Temp = 0xBF; break; case BIT.b7: Num = 7; Temp = 0x7F; break; } //データの出力 byte Data = 0; switch (data) { case OUT.H: Data = 1; break; case OUT.L: Data = 0; break; } //指定ビット以外はそのままにして出力データを決定する byte OutputValue = (byte)((buffOutData & Temp) | (Data << Num));//byteでキャストしないと怒られる //出力データバッファの更新 switch (pName) { case PORT.P0: this.p0Outdata = OutputValue; break; case PORT.P1: this.p1Outdata = OutputValue; break; case PORT.P2: this.p2Outdata = OutputValue; break; case PORT.P3: this.p3Outdata = OutputValue; break; case PORT.P4: this.p4Outdata = OutputValue; break; case PORT.P5: this.p5Outdata = OutputValue; break; case PORT.P6: this.p6Outdata = OutputValue; break; case PORT.P7: this.p7Outdata = OutputValue; break; } //データ出力 this.Status = EPX64S_OutputPort(this.hDevice, Port, OutputValue); return((Status == EPX64S_OK) ? true : false); } catch { this.Status = EPX64S.EPX64S_COMMUNICATION_ERROR; return(false); } }
private void btnScan_Click(object sender, EventArgs e) { if (!Directory.Exists(AudioDir)) { try { Directory.CreateDirectory(AudioDir); } catch (Exception ex) { Log.Write("AudioExtract: Unable to create Audio directory"); Log.Write(ex); MessageBox.Show($"Unable to create the output directory. Reason: {ex.Message}", "Can't create directory", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } FileStream FS; try { FS = File.OpenRead(tbResourceFile.Text); } catch (Exception ex) { Log.Write("AudioExtract: Unable to open pak file"); Log.Write(ex); MessageBox.Show($"Unable to open the specified file. Reason: {ex.Message}", "Can't open file", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Disable controls btnScan.Enabled = false; btnSelectFile.Enabled = false; tbResourceFile.Enabled = false; Log.Write("AudioExtract: Begin audio extraction of {0}", tbResourceFile.Text); //Begin audio extraction WaveFinder.FindAudio(FS); pbFilePos.Maximum = 100; Thread T = new Thread(delegate() { while (WaveFinder.IsScanning) { Invoke((MethodInvoker) delegate { pbFilePos.Value = (int)(FS.Position * 100 / FS.Length); }); Thread.Sleep(500); } Log.Write("AudioExtract: Audio extraction complete. Found {0} files", WaveFinder.WaveFiles.Length); using (FS) { int Counter = 0; //Order files descending but PCM first, then OGG var FoundFiles = WaveFinder.WaveFiles .Where(m => m.Type == WaveFileType.PCM) .OrderByDescending(m => m.Header.DataSize) .Concat( WaveFinder.WaveFiles .Where(m => m.Type == WaveFileType.OGG) .OrderByDescending(m => m.Header.DataSize)) .ToArray(); Log.Write("AudioExtract: Exporting {0} files", FoundFiles.Length); Invoke((MethodInvoker) delegate { pbFilePos.Value = 0; pbFilePos.Maximum = FoundFiles.Length; }); foreach (var F in FoundFiles) { var FileName = Path.Combine(AudioDir, string.Format("{0:0000}.{1}", ++Counter, F.Type == WaveFileType.PCM ? "wav" : "ogg")); Invoke((MethodInvoker) delegate { pbFilePos.Value = Counter; }); FileStream OUT; try { OUT = File.Create(FileName); } catch (Exception ex) { Log.Write("AudioExtract: Unable to export {0}", FileName); Log.Write(ex); //Unable to create output file, skip continue; } using (OUT) { FS.Seek(F.Header.DataOffset, SeekOrigin.Begin); if (F.Type == WaveFileType.PCM) { //Fix values before writing new Header //NOTE: Set different values here for different games F.Header.AudioFormat = 1; //PCM F.Header.BitsPerSample = 16; F.Header.SampleRate = 44100; //Fix computed values F.Header.BlockAlign = (ushort)(F.Header.ChannelCount * F.Header.BitsPerSample / 8); F.Header.ByteRate = F.Header.SampleRate * F.Header.ChannelCount * F.Header.BitsPerSample / 8; F.Header.Write(OUT); } else { //OGG Doesn't needs the RIFF header, just write data } byte[] Data = new byte[F.Header.DataSize]; FS.Read(Data, 0, Data.Length); OUT.Write(Data, 0, Data.Length); Log.Write("AudioExtract: Exported {0} file", F.Type); } } } Invoke((MethodInvoker) delegate { pbFilePos.Value = 0; pbFilePos.Maximum = 100; LoadAudioPlayer(); //Enable controls again btnScan.Enabled = true; btnSelectFile.Enabled = true; tbResourceFile.Enabled = true; }); }); T.Start(); }
public static Instruccion DescodificarInstruccion(byte codigo, ushort pos) { Instruccion instruccion = null; ArgMemoria argumentoMemoria = Argumento.ConvertirEnArgumento((Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 1)).Contenido * 256 + Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 2)).Contenido).ToString("X4"), true) as ArgMemoria; ArgRegistro argumentoRegistro = Argumento.ConvertirEnArgumento(Main.ObtenerNombreRegistro(codigo % 4), false) as ArgRegistro; ArgLiteral argumentoLiteral = Argumento.ConvertirEnArgumento(Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 1)).Contenido.ToString(), false) as ArgLiteral; switch (codigo / 8) { case 0: instruccion = new LD(argumentoRegistro); break; case 1: instruccion = new ST(argumentoRegistro); break; case 4: case 5: instruccion = new LDM(argumentoMemoria, argumentoRegistro); break; case 6: case 7: instruccion = new STM(argumentoRegistro, argumentoMemoria); break; case 2: case 3: instruccion = new LDI(argumentoLiteral, argumentoRegistro); break; case 8: instruccion = new ADD(argumentoRegistro); break; case 9: instruccion = new SUB(argumentoRegistro); break; case 10: instruccion = new CMP(argumentoRegistro); break; case 11: instruccion = new INC(); break; case 12: instruccion = new ADI(argumentoLiteral); break; case 13: instruccion = new SUI(argumentoLiteral); break; case 14: case 15: instruccion = new CMI(argumentoLiteral); break; case 16: instruccion = new ANA(argumentoRegistro); break; case 17: instruccion = new ORA(argumentoRegistro); break; case 18: instruccion = new XRA(argumentoRegistro); break; case 19: instruccion = new CMA(); break; case 20: instruccion = new ANI(argumentoLiteral); break; case 21: instruccion = new ORI(argumentoLiteral); break; case 22: case 23: instruccion = new XRI(argumentoLiteral); break; case 24: case 25: instruccion = new JMP(argumentoMemoria); break; case 26: instruccion = new BEQ(argumentoMemoria); break; case 27: instruccion = new BC(argumentoMemoria); break; case 28: case 29: instruccion = new LF(); break; case 30: instruccion = new IN(argumentoMemoria, argumentoRegistro); break; case 31: instruccion = new OUT(argumentoRegistro, argumentoMemoria); break; } return(instruccion); }