calculation of similarity of two vector C#
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have some vectors of data as:
681,305,305,304,667,92.87,254.51,100.24 has "A" as key
and
460,682,702,683,443,89.17,273.83,102.19 has"B" as key
and
593,395,413,418,564,71.13,17.67,83.79 has "C" as key
Then, from my device, I obtained a sample of data and needed to translate it into key. sample of data as below:
593,395,413,418,564,71.13,17.67,83.79
I want to calculate the similarity of the obtained data with the three samples of the above data, see which one is most similar to the obtained data, then I choose key of sample to return. I'm using C#.
Is there any algorithm for calculating it? Please help me, thanks!
c# algorithm
add a comment |
I have some vectors of data as:
681,305,305,304,667,92.87,254.51,100.24 has "A" as key
and
460,682,702,683,443,89.17,273.83,102.19 has"B" as key
and
593,395,413,418,564,71.13,17.67,83.79 has "C" as key
Then, from my device, I obtained a sample of data and needed to translate it into key. sample of data as below:
593,395,413,418,564,71.13,17.67,83.79
I want to calculate the similarity of the obtained data with the three samples of the above data, see which one is most similar to the obtained data, then I choose key of sample to return. I'm using C#.
Is there any algorithm for calculating it? Please help me, thanks!
c# algorithm
2
How should similarity been calculated? This depends on the "meaning" of that data. So you have to define this first. Then you maybe find a routine to calculate it.
– H.G. Sandhagen
Nov 25 '18 at 5:54
Your question is essentially a set of requirements and so is off-topic for SO sadly. How to Ask
– MickyD
Nov 25 '18 at 6:04
Oh, as you can see, first four numbers are the compressive force on the surface. last three numbers shows the compression angle of the surface obtained from the accelerometer
– Gacom111haaa
Nov 25 '18 at 8:23
add a comment |
I have some vectors of data as:
681,305,305,304,667,92.87,254.51,100.24 has "A" as key
and
460,682,702,683,443,89.17,273.83,102.19 has"B" as key
and
593,395,413,418,564,71.13,17.67,83.79 has "C" as key
Then, from my device, I obtained a sample of data and needed to translate it into key. sample of data as below:
593,395,413,418,564,71.13,17.67,83.79
I want to calculate the similarity of the obtained data with the three samples of the above data, see which one is most similar to the obtained data, then I choose key of sample to return. I'm using C#.
Is there any algorithm for calculating it? Please help me, thanks!
c# algorithm
I have some vectors of data as:
681,305,305,304,667,92.87,254.51,100.24 has "A" as key
and
460,682,702,683,443,89.17,273.83,102.19 has"B" as key
and
593,395,413,418,564,71.13,17.67,83.79 has "C" as key
Then, from my device, I obtained a sample of data and needed to translate it into key. sample of data as below:
593,395,413,418,564,71.13,17.67,83.79
I want to calculate the similarity of the obtained data with the three samples of the above data, see which one is most similar to the obtained data, then I choose key of sample to return. I'm using C#.
Is there any algorithm for calculating it? Please help me, thanks!
c# algorithm
c# algorithm
asked Nov 25 '18 at 5:08
Gacom111haaaGacom111haaa
167
167
2
How should similarity been calculated? This depends on the "meaning" of that data. So you have to define this first. Then you maybe find a routine to calculate it.
– H.G. Sandhagen
Nov 25 '18 at 5:54
Your question is essentially a set of requirements and so is off-topic for SO sadly. How to Ask
– MickyD
Nov 25 '18 at 6:04
Oh, as you can see, first four numbers are the compressive force on the surface. last three numbers shows the compression angle of the surface obtained from the accelerometer
– Gacom111haaa
Nov 25 '18 at 8:23
add a comment |
2
How should similarity been calculated? This depends on the "meaning" of that data. So you have to define this first. Then you maybe find a routine to calculate it.
– H.G. Sandhagen
Nov 25 '18 at 5:54
Your question is essentially a set of requirements and so is off-topic for SO sadly. How to Ask
– MickyD
Nov 25 '18 at 6:04
Oh, as you can see, first four numbers are the compressive force on the surface. last three numbers shows the compression angle of the surface obtained from the accelerometer
– Gacom111haaa
Nov 25 '18 at 8:23
2
2
How should similarity been calculated? This depends on the "meaning" of that data. So you have to define this first. Then you maybe find a routine to calculate it.
– H.G. Sandhagen
Nov 25 '18 at 5:54
How should similarity been calculated? This depends on the "meaning" of that data. So you have to define this first. Then you maybe find a routine to calculate it.
– H.G. Sandhagen
Nov 25 '18 at 5:54
Your question is essentially a set of requirements and so is off-topic for SO sadly. How to Ask
– MickyD
Nov 25 '18 at 6:04
Your question is essentially a set of requirements and so is off-topic for SO sadly. How to Ask
– MickyD
Nov 25 '18 at 6:04
Oh, as you can see, first four numbers are the compressive force on the surface. last three numbers shows the compression angle of the surface obtained from the accelerometer
– Gacom111haaa
Nov 25 '18 at 8:23
Oh, as you can see, first four numbers are the compressive force on the surface. last three numbers shows the compression angle of the surface obtained from the accelerometer
– Gacom111haaa
Nov 25 '18 at 8:23
add a comment |
2 Answers
2
active
oldest
votes
There are many possible approaches:
Calculate Minkowski distances between possible pairs and choose the closest.
For every two arrays A and B, you can calculate an array of differences/deltas D, where Di = |Ai - Bi|. For this array you can calculate mean, variance, maybe other moments and infer from it.
...
But how you will use these quantities depends on the meaning of your data and on how it will impact performance.
As you pointed out in the comment, the data actually contains two parts: forces and angles, so most likely you need to compare not the whole arrays, but two subarrays of lengths 4 and 3.
Currently I am using Euclidean Distance and mean, let me try adding other types, thank you.
– Gacom111haaa
Nov 26 '18 at 2:40
add a comment |
There can be several assumptions based upon that you may make decision for similarity. I have presented a simple program in C#
for finding similarity based upon the summation of absolute difference between values in same indices. The one with minimum summation will be most similar. You may extend your solution in similar manner.
using System;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Dictionary<string, List<double> > map = new Dictionary<string, List<double> >();
List<double>listA = new List<double>(new double{681,305,305,304,667,92.87,254.51,100.24});
map.Add("A", listA);
List<double>listB = new List<double>(new double{460,682,702,683,443,89.17,273.83,102.19});
map.Add("B", listB);
List<double>listC = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
map.Add("C", listC);
List<double>testList = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
string ans = mostSimilarKey(testList, map);
Console.WriteLine("Most similar key is: "+ans);
}
static string mostSimilarKey(List<double>testList, Dictionary<string, List<double> > map) {
double minDifference = Double.MaxValue;
string ans = "";
foreach (var pair in map) {
double absoluteDifference = getAbsoluteDifference(testList, pair.Value);
if (absoluteDifference < minDifference) {
minDifference = absoluteDifference;
ans = pair.Key;
}
}
return ans;
}
static double getAbsoluteDifference(List<double>testList, List<double>list) {
double absoluteDifference = 0.0;
for (int i = 0; i < testList.Count; ++i) {
absoluteDifference += Math.Abs(testList[i] - list[i]);
}
return absoluteDifference;
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464824%2fcalculation-of-similarity-of-two-vector-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are many possible approaches:
Calculate Minkowski distances between possible pairs and choose the closest.
For every two arrays A and B, you can calculate an array of differences/deltas D, where Di = |Ai - Bi|. For this array you can calculate mean, variance, maybe other moments and infer from it.
...
But how you will use these quantities depends on the meaning of your data and on how it will impact performance.
As you pointed out in the comment, the data actually contains two parts: forces and angles, so most likely you need to compare not the whole arrays, but two subarrays of lengths 4 and 3.
Currently I am using Euclidean Distance and mean, let me try adding other types, thank you.
– Gacom111haaa
Nov 26 '18 at 2:40
add a comment |
There are many possible approaches:
Calculate Minkowski distances between possible pairs and choose the closest.
For every two arrays A and B, you can calculate an array of differences/deltas D, where Di = |Ai - Bi|. For this array you can calculate mean, variance, maybe other moments and infer from it.
...
But how you will use these quantities depends on the meaning of your data and on how it will impact performance.
As you pointed out in the comment, the data actually contains two parts: forces and angles, so most likely you need to compare not the whole arrays, but two subarrays of lengths 4 and 3.
Currently I am using Euclidean Distance and mean, let me try adding other types, thank you.
– Gacom111haaa
Nov 26 '18 at 2:40
add a comment |
There are many possible approaches:
Calculate Minkowski distances between possible pairs and choose the closest.
For every two arrays A and B, you can calculate an array of differences/deltas D, where Di = |Ai - Bi|. For this array you can calculate mean, variance, maybe other moments and infer from it.
...
But how you will use these quantities depends on the meaning of your data and on how it will impact performance.
As you pointed out in the comment, the data actually contains two parts: forces and angles, so most likely you need to compare not the whole arrays, but two subarrays of lengths 4 and 3.
There are many possible approaches:
Calculate Minkowski distances between possible pairs and choose the closest.
For every two arrays A and B, you can calculate an array of differences/deltas D, where Di = |Ai - Bi|. For this array you can calculate mean, variance, maybe other moments and infer from it.
...
But how you will use these quantities depends on the meaning of your data and on how it will impact performance.
As you pointed out in the comment, the data actually contains two parts: forces and angles, so most likely you need to compare not the whole arrays, but two subarrays of lengths 4 and 3.
answered Nov 25 '18 at 10:37
YolaYola
11.5k64774
11.5k64774
Currently I am using Euclidean Distance and mean, let me try adding other types, thank you.
– Gacom111haaa
Nov 26 '18 at 2:40
add a comment |
Currently I am using Euclidean Distance and mean, let me try adding other types, thank you.
– Gacom111haaa
Nov 26 '18 at 2:40
Currently I am using Euclidean Distance and mean, let me try adding other types, thank you.
– Gacom111haaa
Nov 26 '18 at 2:40
Currently I am using Euclidean Distance and mean, let me try adding other types, thank you.
– Gacom111haaa
Nov 26 '18 at 2:40
add a comment |
There can be several assumptions based upon that you may make decision for similarity. I have presented a simple program in C#
for finding similarity based upon the summation of absolute difference between values in same indices. The one with minimum summation will be most similar. You may extend your solution in similar manner.
using System;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Dictionary<string, List<double> > map = new Dictionary<string, List<double> >();
List<double>listA = new List<double>(new double{681,305,305,304,667,92.87,254.51,100.24});
map.Add("A", listA);
List<double>listB = new List<double>(new double{460,682,702,683,443,89.17,273.83,102.19});
map.Add("B", listB);
List<double>listC = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
map.Add("C", listC);
List<double>testList = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
string ans = mostSimilarKey(testList, map);
Console.WriteLine("Most similar key is: "+ans);
}
static string mostSimilarKey(List<double>testList, Dictionary<string, List<double> > map) {
double minDifference = Double.MaxValue;
string ans = "";
foreach (var pair in map) {
double absoluteDifference = getAbsoluteDifference(testList, pair.Value);
if (absoluteDifference < minDifference) {
minDifference = absoluteDifference;
ans = pair.Key;
}
}
return ans;
}
static double getAbsoluteDifference(List<double>testList, List<double>list) {
double absoluteDifference = 0.0;
for (int i = 0; i < testList.Count; ++i) {
absoluteDifference += Math.Abs(testList[i] - list[i]);
}
return absoluteDifference;
}
}
add a comment |
There can be several assumptions based upon that you may make decision for similarity. I have presented a simple program in C#
for finding similarity based upon the summation of absolute difference between values in same indices. The one with minimum summation will be most similar. You may extend your solution in similar manner.
using System;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Dictionary<string, List<double> > map = new Dictionary<string, List<double> >();
List<double>listA = new List<double>(new double{681,305,305,304,667,92.87,254.51,100.24});
map.Add("A", listA);
List<double>listB = new List<double>(new double{460,682,702,683,443,89.17,273.83,102.19});
map.Add("B", listB);
List<double>listC = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
map.Add("C", listC);
List<double>testList = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
string ans = mostSimilarKey(testList, map);
Console.WriteLine("Most similar key is: "+ans);
}
static string mostSimilarKey(List<double>testList, Dictionary<string, List<double> > map) {
double minDifference = Double.MaxValue;
string ans = "";
foreach (var pair in map) {
double absoluteDifference = getAbsoluteDifference(testList, pair.Value);
if (absoluteDifference < minDifference) {
minDifference = absoluteDifference;
ans = pair.Key;
}
}
return ans;
}
static double getAbsoluteDifference(List<double>testList, List<double>list) {
double absoluteDifference = 0.0;
for (int i = 0; i < testList.Count; ++i) {
absoluteDifference += Math.Abs(testList[i] - list[i]);
}
return absoluteDifference;
}
}
add a comment |
There can be several assumptions based upon that you may make decision for similarity. I have presented a simple program in C#
for finding similarity based upon the summation of absolute difference between values in same indices. The one with minimum summation will be most similar. You may extend your solution in similar manner.
using System;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Dictionary<string, List<double> > map = new Dictionary<string, List<double> >();
List<double>listA = new List<double>(new double{681,305,305,304,667,92.87,254.51,100.24});
map.Add("A", listA);
List<double>listB = new List<double>(new double{460,682,702,683,443,89.17,273.83,102.19});
map.Add("B", listB);
List<double>listC = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
map.Add("C", listC);
List<double>testList = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
string ans = mostSimilarKey(testList, map);
Console.WriteLine("Most similar key is: "+ans);
}
static string mostSimilarKey(List<double>testList, Dictionary<string, List<double> > map) {
double minDifference = Double.MaxValue;
string ans = "";
foreach (var pair in map) {
double absoluteDifference = getAbsoluteDifference(testList, pair.Value);
if (absoluteDifference < minDifference) {
minDifference = absoluteDifference;
ans = pair.Key;
}
}
return ans;
}
static double getAbsoluteDifference(List<double>testList, List<double>list) {
double absoluteDifference = 0.0;
for (int i = 0; i < testList.Count; ++i) {
absoluteDifference += Math.Abs(testList[i] - list[i]);
}
return absoluteDifference;
}
}
There can be several assumptions based upon that you may make decision for similarity. I have presented a simple program in C#
for finding similarity based upon the summation of absolute difference between values in same indices. The one with minimum summation will be most similar. You may extend your solution in similar manner.
using System;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
Dictionary<string, List<double> > map = new Dictionary<string, List<double> >();
List<double>listA = new List<double>(new double{681,305,305,304,667,92.87,254.51,100.24});
map.Add("A", listA);
List<double>listB = new List<double>(new double{460,682,702,683,443,89.17,273.83,102.19});
map.Add("B", listB);
List<double>listC = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
map.Add("C", listC);
List<double>testList = new List<double>(new double{593,395,413,418,564,71.13,17.67,83.79});
string ans = mostSimilarKey(testList, map);
Console.WriteLine("Most similar key is: "+ans);
}
static string mostSimilarKey(List<double>testList, Dictionary<string, List<double> > map) {
double minDifference = Double.MaxValue;
string ans = "";
foreach (var pair in map) {
double absoluteDifference = getAbsoluteDifference(testList, pair.Value);
if (absoluteDifference < minDifference) {
minDifference = absoluteDifference;
ans = pair.Key;
}
}
return ans;
}
static double getAbsoluteDifference(List<double>testList, List<double>list) {
double absoluteDifference = 0.0;
for (int i = 0; i < testList.Count; ++i) {
absoluteDifference += Math.Abs(testList[i] - list[i]);
}
return absoluteDifference;
}
}
answered Nov 25 '18 at 6:31
Bishal GautamBishal Gautam
878619
878619
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464824%2fcalculation-of-similarity-of-two-vector-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
How should similarity been calculated? This depends on the "meaning" of that data. So you have to define this first. Then you maybe find a routine to calculate it.
– H.G. Sandhagen
Nov 25 '18 at 5:54
Your question is essentially a set of requirements and so is off-topic for SO sadly. How to Ask
– MickyD
Nov 25 '18 at 6:04
Oh, as you can see, first four numbers are the compressive force on the surface. last three numbers shows the compression angle of the surface obtained from the accelerometer
– Gacom111haaa
Nov 25 '18 at 8:23