Skip to content

Instantly share code, notes, and snippets.

@kaneta1992
Created April 3, 2020 06:28
Show Gist options
  • Save kaneta1992/ac4642095a755bc719d5e4b74c6e09cf to your computer and use it in GitHub Desktop.
Save kaneta1992/ac4642095a755bc719d5e4b74c6e09cf to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
float gauss(float sigma, float x)
{
float sigma2 = sigma * sigma;
return exp(-(x * x) / (2.0f * sigma2));
}
int main()
{
float sum = 0.0f;
float weights[100];
for (int i = 0; i < 11; i++)
{
weights[i] = gauss(2.0f, (float)(i - 5));
sum += weights[i];
}
for (int i = 0; i < 11; i++)
{
weights[i] /= sum;
cout << weights[i] << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment