public IHttpActionResult Putsample(int id, sample sample) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } if (id != sample.sample_Id) { return(this.BadRequest()); } this.db.Entry(sample).State = EntityState.Modified; var sampleExists = this.db.samples.Count(e => e.sample_Id == id) > 0; try { this.db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!sampleExists) { return(this.NotFound()); } throw; } return(this.StatusCode(HttpStatusCode.NoContent)); }
static void Main(string[] args) { sample <int> obj = new sample <int>(test); obj(111); Console.ReadKey(); }
public async Task <IActionResult> Edit(int id, [Bind("idx,title,userName,writeDate")] sample sample) { if (id != sample.idx) { return(NotFound()); } if (ModelState.IsValid) { try { db.Update(sample); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!sampleExists(sample.idx)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(sample)); }
public async Task <IHttpActionResult> EmailStatus(EmailModel em) { IdentityResult result = await UserManager.SetTwoFactorEnabledAsync(em.UserId, em.value); var user = await UserManager.FindByIdAsync(em.UserId); if (user != null) { //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); } // return RedirectToAction("Index", "Manage"); if (!result.Succeeded) { return(GetErrorResult(result)); } if (result.Succeeded && em.value == true) { ValueController obj = new ValueController(); sample google2FA = new sample() { GoogleStatus = obj.GetGoogleStatus(em.UserId) }; if (google2FA.GoogleStatus == true) { obj.ChangeGoogleStatus(em.UserId, false); } } return(Ok()); }
int Main(String[] args) { sample s = new sample(); s.Start(); return(0); }
public int NewSample(int _signal_type, int _id_person) { try { sample newSample = new sample(); newSample.id_person = _id_person; newSample.signal_type = _signal_type; newSample.acquisition_date = DateTime.Now; newSample.frequency = Convert.ToInt32(ConfigurationManager.AppSettings["frequency"]); newSample.unit = ConfigurationManager.AppSettings["Unit"]; db.sample.Add(newSample); //db.sample_data.Add(_data[0]); //db.sample_data.AddRange(_data); //db.Entry(_data).State = EntityState.Added; db.SaveChanges(); return(newSample.Id); } catch (UpdateException ex) { var a = ex.InnerException.Message.Split('\r')[0].ToString(); } return(-1); }
public ActionResult Index() { List <Question> Book = qb.Questions.ToList(); List <choice> Customer = ch.choices.ToList(); //var Book = new List<Question>() //{ // new Question {QuestionId=1, Question1 = "Programming in C#"}, // new Question {QuestionId=2,Question1 = "Programming in C++"}, // new Question {QuestionId=3,Question1 = "Programming in Java"} //}; //var Customer = new List<Answer>() //{ // new Answer {QuestionId=1,AnsId=1, ans1 = "Zain",ans2 = "Hassan",ans3= "Syed",ans4= "ram",Correctans="Zain"}, // new Answer {QuestionId=2,AnsId=2,ans1 = "Hassan",ans2 = "Zain",ans3= "Syed",ans4= "ram",Correctans="Zain"}, // new Answer {QuestionId=3,AnsId=3,ans1= "Syed",ans2 = "Hassan",ans3= "Zain",ans4= "ram",Correctans="Zain" } //}; var CustomerViewModel = new sample { Books = Book, Customers = Customer }; return(View(CustomerViewModel)); }
public void saveSampleData(int _signal_type, int _id_person, List <sample_data> _data) { try { sample newSample = new sample(); newSample.id_person = _id_person; newSample.signal_type = _signal_type; newSample.acquisition_date = DateTime.Now; newSample.frequency = Convert.ToInt32(ConfigurationManager.AppSettings["frequency"]); newSample.unit = ConfigurationManager.AppSettings["Unit"]; foreach (sample_data item in _data) { try { newSample.sample_data.Add(item); } catch (Exception) { throw; } } db.sample.Add(newSample); //db.sample_data.Add(_data[0]); //db.sample_data.AddRange(_data); //db.Entry(_data).State = EntityState.Added; db.SaveChanges(); } catch (UpdateException ex) { var a = ex.InnerException.Message.Split('\r')[0].ToString(); } }
public static void Main() { sample smpl = new sample(); Console.WriteLine(smpl.str1); Console.WriteLine(smpl.str2); Console.ReadLine(); }
private void Dg_samples_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = dg_samples.Rows[e.RowIndex]; signals_persons i = (signals_persons)row.DataBoundItem; sample sample = BL.getSample(i.id); grafico v = new grafico(BL.getDatasamples(i.id), BL.getsignal_typeString(sample.signal_type)); v.ShowDialog(); }
public static void Main() { sample s = new sample(); s.insert(10); Console.WriteLine("Data : {0}", s.data); Console.WriteLine("Data : {0}", s.delete()); Console.ReadLine(); }
public static void Main() { sample s = new sample(); float sum, prod; string output = "NULL"; s.operations(10.5F, 23.4F, out sum, out prod, ref output); Console.WriteLine("\n\n RESULT : Sum = {0} , Prod ={1} ,\n\n Reference String = {2} \n\n", sum, prod, output); Console.ReadKey(); }
static void Main(string[] args) { sample <int> s = new sample <int>(mytestmethod); s(4567); sample <string> st = new sample <string>(mytestmethod2); st("dsdasdhasdggdagd"); Console.ReadKey(); }
public void deleteSample(List <int> list_to_delete) { foreach (int item in list_to_delete) { sample sample_to_delete = db.sample.Where(S => S.Id == item).FirstOrDefault(); db.sample.Remove(sample_to_delete); } db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("idx,title,userName,writeDate")] sample sample) { if (ModelState.IsValid) { db.Add(sample); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sample)); }
void AccessDelegate() { myDel += new sample(Mul); //made the delegate multicast myDel += delegate(int n1, int n2) //annon method { int res = n1 - n2; Console.WriteLine("The subtraction result is " + res); //return res; }; myDel += (num1, num2) => Console.WriteLine("The result of division is " + (num1 / num2)); //lambda expression CallMethods(myDel); //passing the reff as parameter }
public IHttpActionResult Postsample(sample sample) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } this.db.samples.Add(sample); this.db.SaveChanges(); return(this.CreatedAtRoute("DefaultApi", new { id = sample.sample_Id }, sample)); }
public void saveData(sample_data _data) { try { sample sample = db.sample.Where(S => S.Id == _data.id_sample).FirstOrDefault(); sample.sample_data.Add(_data); db.SaveChanges(); } catch (UpdateException ex) { var a = ex.InnerException.Message.Split('\r')[0].ToString(); } }
public ActionResult ChangeGoogleStatus(string userId, bool value)//need Google Enable ------2 { // var userid = User.Identity.GetUserId(); if (value == true) { //bool value = true; try { bool res = obj.ChangeGoogleStatus(userId, value); if (res == true) { //Write code for insert activity log in db sample EmailStatus = Session["EmailStatus"] as sample; if (EmailStatus.TwoFactor == true) { bool result = obj.ChangeEmailStatus(userId, false); //EmailFalse(userId, false); //await ChangeEmailStatus("", ""); } LogOut(); ViewBag.Message = "Your Google Authentication enable...Please"; return(View("GoogleInfo")); } } catch (Exception ex) { TempData["SendAction"] = "Internal Servar Error."; } } else if (value == false) { try { //bool value = false; bool res = obj.ChangeGoogleStatus(userId, value); if (res == true) { //ViewBag.Message = "Your Google Authentication Disable...Please"; // return View("Info"); return(RedirectToAction("Security", "SecurityCenter")); } } catch (Exception ex) { TempData["SendAction"] = "Internal Servar Error."; } } return(null); }
public async Task <IActionResult> sample_action(sample doc, int?idx, string mode_type) { if (idx == null) { #region 저장 doc.use_yn = "Y"; doc.writeDate = DateTime.Now; db.sample.Add(doc); await db.SaveChangesAsync(); #endregion } else { if (mode_type == "D") { #region 사용안함 sample _update = (from a in db.sample where a.idx == idx select a).Single(); _update.use_yn = "N"; await db.SaveChangesAsync(); #endregion } else { #region 수정 doc.writeDate = DateTime.Now; db.Entry(doc).State = EntityState.Modified; await db.SaveChangesAsync(); return(Redirect("/samples/sample_set?idx=" + idx)); #endregion } } return(Redirect("/samples/sample_list")); }
// 작성 및 수정 public IActionResult sample_set(sample doc, int?idx) { //======================================================================================================================================================== var code_sample = db.code_sample.Where(p => p.use_yn != "N").OrderBy(P => P.index_order).Select(c => new { 값 = c.code_id, 이름 = c.code_name }); ViewBag.코드 = new SelectList(code_sample.AsEnumerable(), "값", "이름"); //======================================================================================================================================================== if (idx != null) { doc = db.sample.Single(x => x.idx == idx); } return(View(doc)); }
public override void Finally() { sample __svc__ = (sample)_service; __sample_1 __ctx1__ = (__sample_1)(__svc__._stateMgrs[1]); if (__ctx1__ != null && __ctx1__.__In_msg != null) { __ctx1__.UnrefMessage(__ctx1__.__In_msg); __ctx1__.__In_msg = null; } if (__ctx1__ != null && __ctx1__.__Out_msg != null) { __ctx1__.UnrefMessage(__ctx1__.__Out_msg); __ctx1__.__Out_msg = null; } base.Finally(); }
public override void Finally() { sample __svc__ = (sample)_service; __sample_root_0 __ctx0__ = (__sample_root_0)(__svc__._stateMgrs[0]); if (__svc__.RCV != null) { __svc__.RCV.Close(this, null); __svc__.RCV = null; } if (__svc__.Send != null) { __svc__.Send.Close(this, null); __svc__.Send = null; } base.Finally(); }
void CallMethods(sample s)//receiving the reff as parameter { Console.WriteLine("I have the method as parameter"); try { Console.WriteLine("Please enter the first number"); int num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Please enter the second number"); int num2 = Convert.ToInt32(Console.ReadLine()); s(num1, num2);//call the deletegare which will call the methods //int res = s(num1, num2);//invoking the type //Console.WriteLine("from the return "+res); } catch (FormatException fe) { Console.WriteLine("Your input was not in right format"); } }
void selectSamplesToBroadcast(List <sample> localSampleList, int deviceID) { //maxSampleNetwork: maximum number of samples the network CAN send. //numLocalSamples: number of samples in the frame. //numSamplesToSend: number of samples chosen by the user/app int numLocalSamples = localSampleList.Count; numSamplesToSend = LIM_NUM_SAMPLES_TO_SEND; //Assign the numSamplesToSend = min(maxSampleCount, maxSamples, numSamplesToSend); numSamplesToSend = maxSampleNetwork < numSamplesToSend ? maxSampleNetwork : numSamplesToSend; numSamplesToSend = numLocalSamples < numSamplesToSend ? numLocalSamples : numSamplesToSend; samplesToSend = new sample[numSamplesToSend]; for (int i = 0; i < numSamplesToSend; i++) { samplesToSend[i] = localSampleList[i]; } // Populating the local sample's list with samples generated sample[] localSampleArray = new sample[localSampleList.Count]; for (int i = 0; (i < localSampleList.Count) && (i < LIM_SAMPLES_PER_LOCAL_LIST); i++) { localSampleArray[i] = localSampleList[i]; } //Add to own list if not receiving it from server clientList.Add(localSampleArray); //clientLOS.timestamps.Add(CurrentTimeMillis()); //clientLOS.deviceIDs.Add(deviceID); clientTimestamps.Add(CurrentTimeMillis()); clientDevices.Add(deviceID); // NEW CODE //sample[] localSampleArray = new sample[localSampleList.Count]; //clientList.Add(localSampleArray); }
void boxmethod() { sample s = new sample(); bool b; object ob = "CSHARP"; b = s.obj is int; Console.WriteLine(b); s.obj = x; b = s.obj is int; Console.WriteLine("{0},{1},{2}", s.obj, s.x, b); s.x = (int)s.obj; s.x = 20; b = s.obj is int; Console.WriteLine("{0},{1},{2}", s.obj, s.x, b); s.obj = "CSHARP"; b = s.obj is int; Console.WriteLine("{0},{1},{2}", s.obj, s.x, b); Console.ReadLine(); }
public async System.Threading.Tasks.Task <ActionResult> Security() { var d = CoinsMarketValueController.GetMarkupWithCoinId(); foreach (var r in d) { switch (r.Key) { case 101: mark101 = r.Value; break; case 102: mark102 = r.Value; break; case 103: mark103 = r.Value; break; case 104: mark104 = r.Value; break; case 105: mark105 = r.Value; break; case 106: mark106 = r.Value; break; } } try { ViewBag.BTC = "$" + Math.Round((Convert.ToDecimal(objCoin.BTCCurrentPrice()) + Convert.ToDecimal(mark101)), 2); } catch (Exception ex) { ViewBag.BTC = ex.Message; } try { ViewBag.ETH = "$" + Math.Round((Convert.ToDecimal(objCoin.ETHCurrentPrice()) + Convert.ToDecimal(mark106)), 2); } catch (Exception ex) { ViewBag.ETH = ex.Message; } try { ViewBag.DASH = "$" + Math.Round((Convert.ToDecimal(objCoin.DASHCurrentPrice()) + Convert.ToDecimal(mark102)), 2); } catch (Exception ex) { ViewBag.DASH = ex.Message; } try { ViewBag.LTC = "$" + Math.Round((Convert.ToDecimal(objCoin.LTCCurrentPrice()) + Convert.ToDecimal(mark103)), 2); } catch (Exception ex) { ViewBag.LTC = ex.Message; } try { ViewBag.ETC = "$" + Math.Round((Convert.ToDecimal(objCoin.ETCCurrentPrice()) + Convert.ToDecimal(mark105)), 2); } catch (Exception ex) { ViewBag.ETC = ex.Message; } try { ViewBag.MBC = "$" + Math.Round((Convert.ToDecimal(objCoin.GetMBC_USDCoin()) + Convert.ToDecimal(mark104)), 2); } catch (Exception ex) { ViewBag.MBC = ex.Message; } GetQR(); sample s = new sample { TwoFactor = await UserManager.GetTwoFactorEnabledAsync(User.Identity.GetUserId()), GoogleStatus = obj.GetGoogleStatus(User.Identity.GetUserId()) }; var sm = ValueController.GetSession(User.Identity.GetUserId()); ViewBag.IpWhiteList = sm.IPAdressWhiteList; SVM.s = s; SVM.Sm = sm; Session["EmailStatus"] = s; return(View(SVM)); }
public static void Main() { sample s = new sample(); int num_res = 0; string string_res, output = "NULL"; Console.WriteLine("\nBefore Calling add method with integer arguments \n\n Sum = {0} and Reference String : {1}", num_res, output); Console.WriteLine("\nCalling add method to find the sum of numbers"); s.add(out num_res, ref output, 10, 20, 30, 40, 50, 60); Console.WriteLine("\nSum = {0} and Reference String : {1}", num_res, output); s.add(out num_res, ref output, 10, 20, 30, 40, 50, 60, 22, 56, 32, 12); Console.WriteLine("\nSum = {0} and Reference String : {1}", num_res, output); string_res = ""; output = "NULL"; Console.WriteLine("\nBefore Calling add method with string arguments\n\n Concatenated String = {0} and Reference String : {1}", string_res, output); Console.WriteLine("\nCalling add method to concatante the given words"); s.add(out string_res, ref output, "abc ", "bcd ", "cde ", "def "); Console.WriteLine("\nConcatenaed String = {0} and Reference String : {1}", string_res, output); s.add(out string_res, ref output, "abc ", "def ", "ghi ", "jkl ", "mno "); Console.WriteLine("\nConcatenated String = {0} and Reference String : {1}", string_res, output); Console.ReadKey(); }
private void set_ITest(List<KeyValuePair<int, float[]>> TData) { for (int i = 0; i < TData.Count; i++) { sample s = new sample(); s.features = TData[i].Value; s.d = TData[i].Key; Test_data.Add(s); } }
private void fillSampleList() { sampleList[0] = new sample(" True colors ", render_colors); sampleList[1] = new sample(" Offscreen console ", render_offscreen); sampleList[2] = new sample(" Line drawing ", render_lines); sampleList[3] = new sample(" Noise ", render_noise); sampleList[4] = new sample(" Field of view ", render_fov); sampleList[5] = new sample(" Path finding ", render_path); sampleList[6] = new sample(" Bsp toolkit ", render_bsp); sampleList[7] = new sample(" Image toolkit ", render_image); sampleList[8] = new sample(" Mouse support ", render_mouse); sampleList[9] = new sample(" Name generator ", render_name); }
// ------------------------------------------------------------------------------------------------------ public void clear() { mBuffer = new sample[50]; for (uint i = 0; i < mBuffer.Length; i++) { mBuffer[i] = new sample(-mBuffer.Length+i, 0); } mAverage5 = 0; mAverage15 = 0; mAverage30 = 0; mAverage60 = 0; mMinValue = float.MaxValue; mMaxValue = float.MinValue; mMinTime = float.MaxValue; mMaxTime = float.MinValue; }
/** * calculate the postion of each vertex. this sets up our 3 dimensional grid of voxels * while also sampling each voxel **/ void CalculateVertexPositions() { for (int x = 0; x < voxels.GetLength(0) - 1; x++) { for (int y = 0; y < voxels.GetLength(1) - 1; y++) { for (int z = 0; z < voxels.GetLength(2) - 1; z++) { // default values. voxels [x, y, z].isOnSurface = false; voxels [x, y, z].voxelEdgeMask = 0; voxels [x, y, z].vertexIndex = -1; voxels [x, y, z].cornerMask = 0; int cornerMask = 0; // sample the 8 corners for the voxel and create a corner mask sample[] samples = new sample[8]; for (int i = 0; i < 8; i++) { var offset = voxelCornerOffsets [i]; var pos = GetWorldSpaceSamplePosition(x + (int)offset.x, y + (int)offset.y, z + (int)offset.z); var sample = SampleField(pos); samples [i].value = sample; samples [i].point = pos; cornerMask |= ((sample > threshold) ? (1 << i) : 0); } //Check for early termination if cell does not intersect boundary if (cornerMask == 0 || cornerMask == 0xff) { continue; } // get edgemask from table using our corner mask int edgeMask = edgeTable [cornerMask]; int edgeCrossings = 0; var vertPos = Vector3.zero; for (int i = 0; i < 12; ++i) { //Use edge mask to check if it is crossed if (!((edgeMask & (1 << i)) > 0)) { continue; } //If it did, increment number of edge crossings ++edgeCrossings; //Now find the point of intersection int e0 = cubeEdges[i << 1]; int e1 = cubeEdges[(i << 1) + 1]; float g0 = samples[e0].value; float g1 = samples[e1].value; float t = (threshold - g0) / (g1 - g0); vertPos += Vector3.Lerp(samples [e0].point, samples [e1].point, t); } vertPos /= edgeCrossings; voxels [x, y, z].vertexPosition = vertPos; voxels [x, y, z].isOnSurface = true; voxels [x, y, z].voxelEdgeMask = edgeMask; voxels [x, y, z].vertexIndex = vertices.Count; voxels [x, y, z].cornerMask = cornerMask; vertices.Add(vertPos); } } } }
/* * Input parameter includes the u,v texture samples, this method * will collect the radiance samples from the pixel values corresponding to * cubemap face. */ void generateRadianceSamples(List <sample> samples) { // Initialize variables Ray ray; RaycastHit hit; Vector3 outDirection; float hitLength = 5.0f; float u, v; // Sample generation variables from respective cubemap. int screen_i, screen_j; int numHitRays = 0; List <float> deviations = new List <float>(); // Radiance Sampling //BEGIN SPIRAL COORDS int x, y, dx, dy; int X = probeSampleSize; int Y = probeSampleSize; x = y = dx = 0; // initialized to -1 because first pixel delta corresponds to -1 to 0 dy = -1; int t = probeSampleSize; int maxI = t * t; // max # pixels. int counter = 0; //Color32 pixeltemp = pixels[(iii + (probeSampleSize - jjj - 1) * probeSampleSize)]; for (int ii = 0; ii < maxI && numHitRays < LIM_SAMPLES_PER_LOCAL_LIST; ii = ii + 1) { // Check corresponding locations for spiral effect of pixel center. if ((x == y) || ((x < 0) && (x == -y)) || ((x > 0) && (x == 1 - y))) { t = dx; // Accumulated texture size. dx = -dy; // Increment the delta x dy = t; // Y is the texture size 'tracker' } // Assign new pixel index of x & y. x += dx; y += dy; // I and J assigned respective rows/columns of 'WIP' texture. int i = x + probeSampleSize / 2; int j = y + probeSampleSize / 2 - 1; //END SPIRAL COORDS // float spx = colWebTexPos.x + screen_i - (((probeSampleSize / 2 - camwidth / 2) / calcratio) + mainCamPixWidth / 2); // float spy = colWebTexPos.y + screen_j - (((probeSampleSize / 2 - camheight / 2) / calcratio) + mainCamPixHeight / 2); float spx = x + samplePosX + probeSampleSize / 2; float spy = samplePosY + probeSampleSize / 2 - y; // Sampling space with respect to collider position (depth z) Vector3 newCoord = new Vector3(spx, spy, colWebTexPos.z); // Raycasting from screen pixel Vector3 rayCoordinateOnScreen = newCoord; // Shoot ray from sample space with respect to collider position. ray = sampleCamera.ScreenPointToRay(rayCoordinateOnScreen); // Check if screen space sample pixel collides with reflective probe. bool coll = probeCollider.Raycast(ray, out hit, hitLength); if (coll) // If raycast collides with the collider { if ((i + (probeSampleSize - 1 - j) * probeSampleSize) >= pixels.Length || (i + (probeSampleSize - 1 - j) * probeSampleSize) < 0) { } else { //Color32 pixel = new Color32((byte)(i * 255.0f / probeSampleSize), (byte)(j * 255.0f / probeSampleSize), 0, 255);// Color32 pixel = pixels[(i + (probeSampleSize - 1 - j) * probeSampleSize)]; // Generating samples // We have angle of incidence, here we calculate the angle from environment. outDirection = Vector3.Reflect(ray.direction, hit.normal); // Point on cube is calculated by taking respective vector on iteration to scale into set of // weighted distance. Vector3 pointOnCube = new Vector3(outDirection.x / Mathf.Max(Mathf.Abs(outDirection.x), Mathf.Abs(outDirection.y), Mathf.Abs(outDirection.z)), outDirection.y / Mathf.Max(Mathf.Abs(outDirection.x), Mathf.Abs(outDirection.y), Mathf.Abs(outDirection.z)), outDirection.z / Mathf.Max(Mathf.Abs(outDirection.x), Mathf.Abs(outDirection.y), Mathf.Abs(outDirection.z))); dev = calcDeviations(-outDirection, transform.position - sampleCamera.transform.position); //if (dev > 120.0f) //continue; if (pointOnCube.x >= .99f) { face = CubemapFace.PositiveX; u = (-(pointOnCube.z) + 1) / 2; v = ((pointOnCube.y) + 1) / 2; } else if (pointOnCube.x <= -.99f) { face = CubemapFace.NegativeX; u = ((pointOnCube.z) + 1) / 2; v = ((pointOnCube.y) + 1) / 2; } else if (pointOnCube.y >= .99f) { face = CubemapFace.PositiveY; u = ((pointOnCube.x) + 1) / 2; v = (-(pointOnCube.z) + 1) / 2; } else if (pointOnCube.y <= -.99f) { face = CubemapFace.NegativeY; u = ((pointOnCube.x) + 1) / 2; v = ((pointOnCube.z) + 1) / 2; } else if (pointOnCube.z >= .99f) { face = CubemapFace.PositiveZ; u = ((pointOnCube.x) + 1) / 2; v = ((pointOnCube.y) + 1) / 2; } else if (pointOnCube.z <= -.99f) { face = CubemapFace.NegativeZ; u = (-(pointOnCube.x) + 1) / 2; v = ((pointOnCube.y) + 1) / 2; } else { face = CubemapFace.PositiveX; u = 0; v = 0; } sample sample = new sample(); //text = text + dev + "\n"; ////pixel = Color.Lerp(pixel, Color.black, dev/150.0f); //pixel.r = (byte)((1 - (dev / 180.0f)) * pixel.r); //pixel.g = (byte)((1 - (dev / 180.0f)) * pixel.g); //pixel.b = (byte)((1 - (dev / 180.0f)) * pixel.b); //pixel = new Color32(); pixel.a = (byte)((1 - ((dev / 180.0f) * (dev / 180.0f))) * 255); //pixel.r = (byte)(i * 255.0f / probeSampleSize); //pixel.g = (byte)(j * 255.0f / probeSampleSize); //pixel.b = 0; //sample.alpha = (short)((1 - (dev / 180.0f)) * 255); sample.face = face; sample.u = u; sample.v = v; sample.pixel = pixel; samples.Add(sample); numHitRays++; counter++; } } } //writeToFile("./rawData.txt", text, false); return; }
private void kMeans(int k) { #region Create Output layer for (int i = 0; i < 5; i++) // Construct the output Layer { Perceptron per = new Perceptron(k); OutPut.Add(per); } #endregion #region Get_Cntres // Get Random Centers For Clusters Random rd = new Random(); for (int i = 0; i < k; i++) { cluster temp = new cluster(); temp.center = Training_data[rd.Next(0, Training_data.Count)]; Cluster.Add((temp)); KeyValuePair<int, float[]> ls = new KeyValuePair<int, float[]>(); sample s = new sample(); s.copysample(temp.center); old_centers.Add(s); } #endregion // old_centers[0].Value[0] = Training_data[rd.Next(0,Training_data.Count)].Value[0]; old_centers[0].features[0] = (float)-0.0002; while (chek()) { List<double> _out = new List<double>(); #region updateing_old_centers for (int i = 0; i < k; i++) { Cluster[i].cluster_samples.Clear(); old_centers[i].copysample(Cluster[i].center); } #endregion #region Clustring //Clustering // Here's a trap for (int i = 0; i < Training_data.Count; i++) // outer one { //for (int z = 0; z < Training_data[i].Count; z++) { _out.Clear(); for (int j = 0; j < k; j++) { _out.Add(distance(Training_data[i].features, Cluster[j].center.features)); } Cluster[get_min(_out)].cluster_samples.Add(Training_data[i]); } } #endregion #region get new centers for (int c = 0; c < k; c++) { double[] x = new double[128]; for (int i = 0; i < Cluster[c].cluster_samples.Count; i++) { for (int j = 0; j < 128; j++) { x[j] += Convert.ToDouble(Cluster[c].cluster_samples[i].features[j]); } } if (Cluster[c].cluster_samples.Count != 0) { for (int sd = 0; sd < 128; sd++) { x[sd] /= Cluster[c].cluster_samples.Count; } // Cluster[c].center.; for (int sd = 0; sd < 128; sd++) { Cluster[c].center.features[sd] = (float)(x[sd]); } } } #endregion } }
/* Read a specific sample for a specified unit in a RAW format */ /* Returns MinValue if fails */ public short readRawValue(units unitType, sample sampleNum) { short result = short.MinValue; commands command = commands.CMD_UNKNOWN; switch (unitType) { case units.TEMPERATURE: command = commands.CMD_GETTEMP_C_RAW; break; case units.HUMIDITY: command = commands.CMD_GETHUM_RAW; break; case units.PRESSURE: command = commands.CMD_GETPRESS_RAW; break; } this.sendCommand(command, (Byte)sampleNum); if (this.readAnswer(command)) { result = this.decodeShortValue(); } return result; }
void DataProcessing(List<ImageFeature<float>[]> TrainD , List<int> desired ) { for (int imgeindx = 0; imgeindx < TrainD.Count();imgeindx++ ) { for (int descindx = 0 ; descindx < TrainD[imgeindx].Count();descindx++) { sample temp = new sample(); for (int i = 0; i < TrainD[imgeindx][descindx].Descriptor.Count(); i++ ) { temp.features[i] = TrainD[imgeindx][descindx].Descriptor[i]; temp.d = desired[imgeindx]; } Training_data.Add(temp); } } }
void K_Means(int K) { #region Create Output layer for (int i = 0; i < 5; i++) // Construct the output Layer { Perceptron per = new Perceptron(K); OutPut.Add(per); } #endregion #region Get_Cntres // Get Random Centers For Clusters Random rd = new Random(); for (int i = 0; i < K; i++) { cluster temp = new cluster(); temp.center = Training_data[rd.Next(0, Training_data.Count)]; Clusters.Add((temp)); sample s = new sample(); s.copysample(temp.center); old_centers.Add(s); } #endregion old_centers[0].features[0] = (float)-0.0002; // To change it for first time while (check() ) { #region updateing_old_centers for (int i = 0; i < K; i++) { Clusters[i].cluster_samples.Clear(); old_centers[i].copysample(Clusters[i].center); } #endregion #region Clustering List<double> _out = new List<double>(); for (int sampleindx = 0; sampleindx < Training_data.Count(); sampleindx ++ ) { _out.Clear(); for (int Clusterindx = 0; Clusterindx < Clusters.Count(); Clusterindx ++ ) { _out.Add(distance(Training_data[sampleindx].features, Clusters[Clusterindx].center.features)); } Clusters[get_min(_out)].cluster_samples.Add(Training_data[sampleindx]); } #endregion #region Get New Centers for (int clusterindx = 0; clusterindx < Clusters.Count(); clusterindx ++ ) { double[] x = new double[Clusters[clusterindx].center.features.Count()]; for (int sampleindx = 0 ; sampleindx < Clusters[clusterindx].cluster_samples.Count ; sampleindx++) { for (int featureindx = 0; featureindx < Clusters[clusterindx].center.features.Count(); featureindx++ ) { x[featureindx] += Clusters[clusterindx].cluster_samples[sampleindx].features[featureindx]; } } for (int featureindx = 0; featureindx < Clusters[clusterindx].center.features.Count(); featureindx++) { x[featureindx] /= Clusters[clusterindx].cluster_samples.Count(); Clusters[clusterindx].center.features[featureindx] = (float) x[featureindx]; // update new centers } } #endregion } }
void TestDataProcessing(ImageFeature<float>[] TrainD) { for (int imgeindx = 0; imgeindx < TrainD.Count(); imgeindx++) { // for (int descindx = 0; descindx < TrainD[imgeindx].Count(); descindx++) { sample temp = new sample(); for (int i = 0; i < TrainD[imgeindx].Descriptor.Count(); i++) { temp.features[i] = TrainD[imgeindx].Descriptor[i]; } Testing_data.Add(temp); } } }
public cluster() { cluster_samples = new List<sample>(); center = new sample(); }
public void copysample(sample s) { this.d = s.d; s.features.CopyTo(this.features, 0); }