fixed errors
This commit is contained in:
parent
875d4bd72e
commit
dea72060c2
3 changed files with 62 additions and 56 deletions
|
|
@ -18,26 +18,26 @@ using namespace std;
|
|||
|
||||
tuple<double, double, double> means0(double a, double b, double c){
|
||||
double arith = (a+b+c) / 3;
|
||||
double geo = pow((a*b*c), 1.0f/3);
|
||||
double harm = 3 / ((1.0f/a) + (1.0f/b) + (1.0f/c));
|
||||
double geo = pow((a*b*c), 1.0/3);
|
||||
double harm = 3 / ((1.0/a) + (1.0/b) + (1.0/c));
|
||||
return make_tuple(arith, geo, harm);
|
||||
}
|
||||
|
||||
tuple<double, double, double> means(const vector<double>& v){
|
||||
int n = v.size();
|
||||
size_t n = v.size();
|
||||
double sum = 0;
|
||||
double prod = 1;
|
||||
double logsum = 0;
|
||||
double invsum = 0;
|
||||
|
||||
for (int i = 0; i<n; ++i){
|
||||
for (size_t i = 0; i<n; ++i){
|
||||
sum += v[i];
|
||||
prod *= v[i];
|
||||
invsum += 1.0f/v[i];
|
||||
logsum += log(v[i]);
|
||||
invsum += 1.0/v[i];
|
||||
}
|
||||
|
||||
double arith = sum / n;
|
||||
double geo = pow(prod, 1.0f/n);
|
||||
double harm = n / invsum;
|
||||
double arith = sum / static_cast<double>(n);
|
||||
double geo = exp(1.0/static_cast<double>(n) * logsum);
|
||||
double harm = static_cast<double>(n) / invsum;
|
||||
return make_tuple(arith, geo, harm);
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ void write_vector_to_file(const string& file_name, const vector<double>& v)
|
|||
ofstream fout(file_name); // Oeffne das File im ASCII-Modus
|
||||
if( fout.is_open() )
|
||||
{
|
||||
for (unsigned int k=0; k<v.size(); ++k)
|
||||
for (size_t k=0; k<v.size(); ++k)
|
||||
{
|
||||
fout << v.at(k) << endl;
|
||||
}
|
||||
|
|
@ -100,10 +100,10 @@ void write_vector_to_file(const string& file_name, const vector<double>& v)
|
|||
|
||||
// -------------- Task C --------------
|
||||
|
||||
double sum_of_spec(int n)
|
||||
long int sum_of_spec(int n)
|
||||
{
|
||||
long int sum = 0;
|
||||
for (int i=1; i<n+1; i++){
|
||||
for (long int i=1; i<n+1; i++){
|
||||
if (i % 3 == 0 || i % 5 == 0){
|
||||
sum += i;
|
||||
}
|
||||
|
|
@ -113,13 +113,13 @@ double sum_of_spec(int n)
|
|||
|
||||
double formula(int n)
|
||||
{
|
||||
double div_by_3 = floor( n / 3.0f );
|
||||
double div_by_5 = floor( n / 5.0f );
|
||||
double div_by_15 = floor( n / 15.0f );
|
||||
double div_by_3 = floor( n / 3.0 );
|
||||
double div_by_5 = floor( n / 5.0 );
|
||||
double div_by_15 = floor( n / 15.0 );
|
||||
|
||||
double S_3 = 3.0 * (div_by_3*((div_by_3+1)/2.0f));
|
||||
double S_5 = 5.0 * (div_by_5*((div_by_5+1)/2.0f));
|
||||
double S_15 = 15.0 * (div_by_15*((div_by_15+1)/2.0f));
|
||||
double S_3 = 3.0 * (div_by_3*((div_by_3+1)/2.0));
|
||||
double S_5 = 5.0 * (div_by_5*((div_by_5+1)/2.0));
|
||||
double S_15 = 15.0 * (div_by_15*((div_by_15+1)/2.0));
|
||||
|
||||
double sum = S_3 + S_5 - S_15;
|
||||
|
||||
|
|
@ -215,15 +215,15 @@ double DenseMatrix::sigmoid(double x)
|
|||
return 1.0 / (1.0 + exp(-x));
|
||||
}
|
||||
|
||||
DenseMatrix::DenseMatrix(int n, int m) : rows(n), cols(m), matrix(n*m)
|
||||
DenseMatrix::DenseMatrix(size_t n, size_t m) : rows(n), cols(m), matrix(n*m)
|
||||
{
|
||||
int nm = max(n, m);
|
||||
size_t nm = max(n, m);
|
||||
for (size_t i = 0; i < rows; i++)
|
||||
{
|
||||
for (size_t j = 0; j < cols; j++)
|
||||
{
|
||||
double x_i = 10.0*i/(nm-1) - 5.0;
|
||||
double x_j = 10.0*j/(nm-1) - 5.0;
|
||||
double x_i = 10.0*static_cast<double>(i)/(nm-1) - 5.0;
|
||||
double x_j = 10.0*static_cast<double>(j)/(nm-1) - 5.0;
|
||||
matrix[i*cols + j] = sigmoid(x_i) * sigmoid(x_j);
|
||||
}
|
||||
}
|
||||
|
|
@ -260,7 +260,7 @@ vector<double> DenseMatrix::MultT(const vector<double>& vec) const
|
|||
}
|
||||
|
||||
void DenseMatrix::print() const {
|
||||
int count(0);
|
||||
size_t count(0);
|
||||
cout.precision(5);
|
||||
for (double val : matrix) {
|
||||
printf("%.6f ", val);
|
||||
|
|
@ -308,4 +308,13 @@ vector<double> DenseMatrix2::MultT(const vector<double>& vec) const
|
|||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void task_a();
|
||||
void task_b();
|
||||
void task_c();
|
||||
void task_d();
|
||||
void task_e();
|
||||
void task_f();
|
||||
void task_g();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue