/// <summary> /// Складывает два массива типа int и возвращает новый /// </summary> /// <param name="arr1">Массив 1</param> /// <param name="arr2">Массив 2</param> /// <returns>int[]</returns> public static int[] sumIntArr(int[] arr1, int[] arr2, ArrayOperation operation = ArrayOperation.Plus) { if (arr1.Length != arr2.Length) { new Exception("Количество элементов в массиве должно совпадать"); } int[] resArr = new int[arr1.Length]; for (int i = 0; i < arr1.Length; i++) { switch (operation) { case ArrayOperation.Plus: resArr[i] = arr1[i] + arr2[i]; break; case ArrayOperation.Minus: resArr[i] = arr1[i] - arr2[i]; break; case ArrayOperation.Multiplication: resArr[i] = arr1[i] * arr2[i]; break; case ArrayOperation.Division: resArr[i] = (int)(arr1[i] / arr2[i]); break; } } return(resArr); }
public TOFFitResults FitTOF(TOF t) { TOFFitResults results = new TOFFitResults(); double[] coefficients = new double[4]; // guess some reasonable values coefficients[0] = t.Data[0]; coefficients[1] = ArrayOperation.GetMax(t.Data) - coefficients[0]; double lastT = t.Times[t.Times.Length - 1]; coefficients[2] = (t.Times[0] + lastT) / 2; coefficients[3] = (lastT - t.Times[0]) / 5; double mse = 0; // this is totally tedious! double[] times = new double[t.Times.Length]; for (int i = 0; i < t.Times.Length; i++) { times[i] = (double)t.Times[i]; } CurveFit.NonLinearFit(times, t.Data, new ModelFunctionCallback(gaussian), coefficients, out mse, 1000000); results.Background = coefficients[0]; results.Amplitude = coefficients[1]; results.Centre = coefficients[2]; results.Width = Math.Abs(coefficients[3]); return(results); }
private void waveformGraph1_Paint(object sender, PaintEventArgs e) { waveformPlot1.PlotY(waveform); // Calculate the single-sided, scaled auto power spectrum of signal // Set the sample period double dt, df; dt = 1.0 / (actualPts); //UnscaledWindow.Blackman(waveform); //UnscaledWindow.BlackmanHarris(waveform); //UnscaledWindow.ExactBlackman(waveform); //UnscaledWindow.FlatTop(waveform); //UnscaledWindow.Hamming(waveform); UnscaledWindow.Hanning(waveform); autoPowerSpectrum = Measurements.AutoPowerSpectrum(waveform, dt, out df); double maximum = ArrayOperation.GetMax(autoPowerSpectrum); //maximum = Math.Sqrt(maximum); for (int i = 0; i < actualPts / 2; i++) { autoPowerSpectrum[i] = 10.0 * Math.Log10(Math.Max(autoPowerSpectrum[i] / maximum, 1.0e-15)); } waveformPlot2.PlotY(autoPowerSpectrum); }
public void test_THAT_array_operation_with_one_operand_IS_converted_to_expression_correctly() { var op1 = new FieldRefOperand("Status"); var op = new ArrayOperation(null, op1); var expr = op.ToExpression(); Assert.That(expr.ToString(), Is.EqualTo("x.get_Item(\"Status\")")); }
public void test_THAT_array_operation_with_single_operands_with_ordering_IS_converted_to_expression_correctly() { var op1 = new FieldRefOperand("Status"); var op11 = new FieldRefOperandWithOrdering(op1, new Camlex.Desc()); var op = new ArrayOperation(null, op11); var expr = op.ToExpression(); Assert.That(expr.ToString(), Is.EqualTo("(x.get_Item(\"Status\") As Desc)")); }
public void test_THAT_array_operation_with_two_operands_IS_converted_to_expression_correctly() { var op1 = new FieldRefOperand("Status"); var op2 = new FieldRefOperand("Title"); var op = new ArrayOperation(null, op1, op2); var expr = op.ToExpression(); Assert.That(expr.ToString(), Is.EqualTo("new [] {x.get_Item(\"Status\"), x.get_Item(\"Title\")}")); }
private void analogInCallback_computeGain(IAsyncResult ar) { double[] state = (double[])ar.AsyncState; int ch = (int)state[0]; double f = state[1]; int reader = (int)state[3]; ButterworthBandpassFilter bwfilt = null; if (checkBox_diagnosticsDigitalFilter.Checked) { bwfilt = new ButterworthBandpassFilter(1, spikeSamplingRate, f - f / 8, f + f / 8); } double[,] data = diagnosticsReaders[reader].EndReadMultiSample(ar); double[] oneChannelData = new double[data.GetLength(1)]; double RMSinput = 0.707106704695506 * Convert.ToDouble(numericUpDown_diagnosticsVoltage.Value); if (checkBox_diagnosticsVotlageDivider.Checked) { RMSinput /= Convert.ToDouble(textBox_voltageDivider.Text); } if (ch != -1 && ch < (reader + 1) * 32 && ch >= reader * 32) //If the channel is not "all channels" it should be in the particular device's range //if (ch > 0) { for (int i = 0; i < data.GetLength(1); ++i) { oneChannelData[i] = data[ch - 1, i]; } //Filter data to bring out pure tone if (checkBox_diagnosticsDigitalFilter.Checked && bwfilt != null) { oneChannelData = bwfilt.FilterData(oneChannelData); } double rms = rootMeanSquared(oneChannelData); //DEBUGGING ch = 1; gains[ch - 1][(int)state[2]] = rms / RMSinput; gains[ch - 1][(int)state[2]] = 20 * Math.Log10(gains[ch - 1][(int)state[2]]); } else if (ch == -1) //Do all channels at once, but this requires special hardware (like Plexon headstage tester) { for (int i = 0; i < numChannels; ++i) { if (checkBox_diagnosticsDigitalFilter.Checked) { oneChannelData = bwfilt.FilterData(ArrayOperation.CopyRow(data, i)); } oneChannelData = ArrayOperation.CopyRow(data, i); double rms = rootMeanSquared(oneChannelData); gains[i][(int)state[2]] = rms / RMSinput; gains[i][(int)state[2]] = 20 * Math.Log10(gains[i][(int)state[2]]); } } }
public ArrayOperationTest() { this._operation = new ArrayOperation(); this._matrix1 = new double[arraySize, arraySize] { { 1, 1, 1, 1 }, { 2, 5, 1, 4 }, { 3, 5, 2, 0 }, { 2, 5, 0, 1 } }; this._vector1 = new double[arraySize] { 1, 2, 3, 4 }; this._vector2 = new double[arraySize] { 5, 0, 1, 3 }; this._vector3 = new double[arraySize] { 5, 6, 7, 8 }; this._valuesToAdd = new double[2] { -1, 1 }; this._nodePositions = new uint[2] { 0, 1 }; this._elementPositions = new uint[2] { 1, 2 }; this._sumVector1Vector2Vector3 = new double[arraySize] { 11, 8, 11, 15 }; this._addedValuesInMatrix1 = new double[arraySize, arraySize] { { 0, 1, 1, 1 }, { 2, 5, 1, 4 }, { 3, 5, 3, 0 }, { 2, 5, 0, 1 } }; this._inversedMatrix1 = new double[arraySize, arraySize] { { 3.5, -1.3, -1.1, 1.7 }, { -1.5, 0.5, 0.5, -0.5 }, { -1.5, 0.7, 0.9, -1.3 }, { 0.5, 0.1, -0.3, 0.1 } }; this._mergedVector1Vetor2 = new double[2 * arraySize] { 1, 2, 3, 4, 5, 0, 1, 3 }; this._multipliedMatrix1Vector1 = new double[arraySize] { 10, 31, 19, 16 }; this._transposedMatrix1 = new double[arraySize, arraySize] { { 1, 2, 3, 2 }, { 1, 5, 5, 5 }, { 1, 1, 2, 0 }, { 1, 4, 0, 1 } }; this._equivalentStiffness = new double[, ] { { 90, -270, 45, 0, 0, 0 }, { -270, 2528.78, 92.1953, 362.195, 0, 0 }, { 45, 92.1953, 210.732, 60.3659, 1.60557e-07, -1.60557e-07 }, { 0, 362.195, 60.3659, 120.732, -1.60557e-07, 1.60557e-07 }, { 0, 0, 1.60557e-07, -1.60557e-07, -6.8633e-07, 6.8633e-07 }, { 0, 0, -1.60557e-07, 1.60557e-07, 6.8633e-07, -6.8633e-07 } }; }
public static void B_CallMulticastDelegate() { int[] myArr = { 2, -4, 10, 5, -6, 9 }; ArrayOperation arrayOperation = ArrayUtils.PrintArray; arrayOperation += ArrayUtils.SortAscending; arrayOperation += ArrayUtils.PrintArray; arrayOperation += ArrayUtils.SortDescending; arrayOperation += ArrayUtils.PrintArray; arrayOperation(myArr); }
public static double[] FitLorenzianToSlaveData(CavityScanData data, double limitLow, double limitHigh) { double mse = 0; double[] voltages = data.parameters.CalculateRampVoltages(); double[] coefficients = new double[] { (data.parameters.High - data.parameters.Low) / 10, voltages[ArrayOperation.GetIndexOfMax(data.SlavePhotodiodeData)], ArrayOperation.GetMax(data.SlavePhotodiodeData) - ArrayOperation.GetMin(data.SlavePhotodiodeData), 0 }; CurveFit.NonLinearFit(voltages, data.SlavePhotodiodeData, new ModelFunctionCallback(lorentzianNarrow), coefficients, out mse, 4000); fitFailSafe(coefficients, limitLow, limitHigh); return(coefficients); }
public void TestMethod_hash() { List <int> list = new List <int>() { 11, 15, 6, 8, 9, 10 }; int[] arr = list.ToArray(); int target = 16; bool result = ArrayOperation.CheckForPair_Hash(arr, target); Assert.AreEqual(result, true); }
/// <summary> /// Creates code from tree /// </summary> /// <param name="tree">The tree</param> /// <param name="ret">Return identifier</param> /// <param name="parameters">Parameters of tree</param> /// <param name="variables">Variables of tree</param> /// <param name="initializers">Initializers</param> /// <returns>List of code strings</returns> protected IList <string> CreateArrayCode(ObjectFormulaTree tree, string ret, string[] parameters, out IList <string> variables, out IList <string> initializers) { List <string> vari = new List <string>(); List <string> init = new List <string>(); variables = vari; initializers = init; IObjectOperation op = tree.Operation; if (!(op is ArrayOperation)) { return(null); } ArrayOperation ao = op as ArrayOperation; object[] types = ao.Types; string[] par = new string[parameters.Length]; for (int i = 0; i < par.Length; i++) { par[i] = GetModifier(types[i]) + parameters[i]; } ArrayReturnType art = ao.ReturnType as ArrayReturnType; List <ObjectFormulaTree> ch = new List <ObjectFormulaTree>(); for (int i = 0; i < tree.Count; i++) { if (tree[i] != null) { ch.Add(tree[i]); } } ObjectFormulaTree t = new ObjectFormulaTree(ao.SingleOperation, ch); List <string> list = new List <string>(); bool success; if (cycle) { ProcessCycleArrayCode(0, tree, t, ret + "[", par, parameters, types, art, list, vari, init, out success); } else { ProcessArrayCode(0, tree, t, ret + "[", par, types, art, list, vari, init, out success); } if (!success) { return(null); } return(list); }
public void test_THAT_operation_IS_rendered_to_caml_properly() { // arrange var fieldRefOperandStub1 = MockRepository.GenerateStub <FieldRefOperand>(""); var fieldRefOperandStub2 = MockRepository.GenerateStub <FieldRefOperand>(""); fieldRefOperandStub1.Stub(o => o.ToCaml()).Return(new XElement("fieldRefOperandStub1")); fieldRefOperandStub2.Stub(o => o.ToCaml()).Return(new XElement("fieldRefOperandStub2")); var resultBuilder = new OperationResultBuilder(); var operation = new ArrayOperation(resultBuilder, fieldRefOperandStub1, fieldRefOperandStub2); // act string caml = operation.ToResult().ToString(); // assert string expected = @"<fieldRefOperandStub1 /> <fieldRefOperandStub2 />"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
private void init() { ArrayOperation.CreateAllArrays(this, new object[] { a }, out y, out yy, out rank, out ranks); returnType = new ArrayReturnType(a, rank, true); }
public string Visit(ArrayOperation operation) { Contract.RequiresNotNull(operation, "operation != null"); return(string.Join(", ", operation.Items.Select(item => Visit(item)))); }
// Train the SALPA filter private void button_Train_Click(object sender, EventArgs e) { thrSALPA = new rawType[Properties.Settings.Default.NumChannels]; this.Cursor = Cursors.WaitCursor; label_noise.Text = "Noise levels not trained."; label_noise.ForeColor = Color.Red; label_noise.Update(); buttonStart.Enabled = false; //So users can't try to get data from the same card int numChannelsPerDevice = (numChannels > 32 ? 32 : numChannels); int numDevices = (numChannels > 32 ? Properties.Settings.Default.AnalogInDevice.Count : 1); spikeTask = new List <Task>(numDevices); for (int i = 0; i < numDevices; ++i) { spikeTask.Add(new Task("SALPATrainingTask_" + i)); for (int j = 0; j < numChannelsPerDevice; ++j) { spikeTask[i].AIChannels.CreateVoltageChannel(Properties.Settings.Default.AnalogInDevice[i] + "/ai" + j.ToString(), "", AITerminalConfiguration.Nrse, -10.0, 10.0, AIVoltageUnits.Volts); } } //Change gain based on comboBox values (1-100) for (int i = 0; i < spikeTask.Count; ++i) { setGain(spikeTask[i], Properties.Settings.Default.A2Dgain); } for (int i = 0; i < spikeTask.Count; ++i) { spikeTask[i].Timing.ReferenceClockSource = "OnboardClock"; } for (int i = 0; i < spikeTask.Count; ++i) { spikeTask[i].Timing.ConfigureSampleClock("", spikeSamplingRate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, Convert.ToInt32(spikeSamplingRate / 2)); } // Set reference clock source for (int i = 0; i < spikeTask.Count; ++i) { spikeTask[i].Timing.ReferenceClockSource = "OnboardClock"; } //Verify the Task for (int i = 0; i < spikeTask.Count; ++i) { spikeTask[i].Control(TaskAction.Verify); } List <AnalogMultiChannelReader> readers = new List <AnalogMultiChannelReader>(spikeTask.Count); for (int i = 0; i < spikeTask.Count; ++i) { readers.Add(new AnalogMultiChannelReader(spikeTask[i].Stream)); } double[][] data = new double[numChannels][]; int c = 0; //Last channel of 'data' written to for (int i = 0; i < readers.Count; ++i) { double[,] tempData = readers[i].ReadMultiSample((int)(NUM_SECONDS_TRAINING * spikeSamplingRate)); //Get a few seconds of "noise" for (int j = 0; j < tempData.GetLength(0); ++j) { data[c++] = ArrayOperation.CopyRow(tempData, j); } } for (int i = 0; i < numChannels; ++i) { thrSALPA[i] = 9 * (rawType)Statistics.Variance(data[i]) / Math.Pow(Properties.Settings.Default.PreAmpGain, 2); Console.Out.WriteLine("channel " + i + ": thr = " + thrSALPA[i]); } //Now, destroy the objects we made for (int i = 0; i < spikeTask.Count; ++i) { spikeTask[i].Dispose(); } spikeTask.Clear(); spikeTask = null; buttonStart.Enabled = true; label_noise.Text = "Noise levels trained."; label_noise.ForeColor = Color.Green; checkBox_SALPA.Enabled = true; this.Cursor = Cursors.Default; }