1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ostrovityanka [42]
3 years ago
11

You will write a program estimate that uses a training data set to learn weights for a set of house attributes, and then applies

those weights to a set of input data to calculate prices for those houses. estimate takes two arguments, which are the paths to files containing the training data and input data.
Computers and Technology
1 answer:
Bumek [7]3 years ago
8 0

Answer:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

double ** transpose(double ** m,int rows,int columns);

double ** multiply(double ** m1,double ** m2,int rows1,int rows2,int columns);

double * vmultiply(double ** m,double * v,int rows,int columns);

double ** inverse(double ** m,int rows);

int main(int argc,char ** argv) {

   FILE * f1 = NULL; //temp file variables

   FILE * f2 = NULL;

   FILE * t = NULL;

   FILE * d = NULL;

   char * filename1 = NULL;

   char * filename2 = NULL;

   char label[20] = {};  

   int columns,rows;

   double ** temp;

   double ** train;

   double ** data;

   double * prices;

   double * weights;

   double ** tr;

   double ** in;

   double ** r1;  

   double ** r2;

   double * r3;

   if (argc != 3) {

       printf("error\n");

       exit(0);

   }

   filename1 = argv[1];

   filename2 = argv[2];

   f1 = fopen(filename1,"r");

   f2 = fopen(filename2,"r");

   if (f1 == NULL || f2 == NULL) {

       printf("error\n");

       exit(0);

   }

   fscanf(f1,"%s\n",label);

   if ((strncmp(label,"train",5) == 0)) {

       t = f1;

       d = f2;

   } else {

       t = f2;

       d = f1;

   }

   fscanf(t,"%d\n",&columns);

   fscanf(t,"%d\n",&rows);

   columns++; //there are k+1 attributes

   train = (double **) malloc(rows * sizeof(double *));

   temp = (double **) malloc(rows * sizeof(double *));

 

   prices = (double *) malloc(rows * sizeof(double *));

   int i;

   for (i = 0; i < rows; i++) {

       train[i] = (double *) malloc(columns * sizeof(double));

       temp[i] = (double *) malloc(columns * sizeof(double));

       train[i][0] = 1; //make the first column all 1s

   }

   int j;

   for (i = 0; i < rows; i++) {

       for (j = 0; j < columns; j++) {

           fscanf(t,"%lf ",&temp[i][j]);

       }

       fscanf(t,"\n");

   }

   for (i = 0; i < rows; i++) {

       for (j = 1; j < columns; j++) {

           train[i][j] = temp[i][j-1];

       }

   }

   for (i = 0; i < rows; i++) {

       prices[i] = temp[i][columns-1];

   }

   tr = transpose(train,rows,columns);

   r1 = multiply(tr,train,columns,rows,columns);

   in = inverse(r1,columns);

   r2 = multiply(in,tr,columns,columns,columns);

   weights = vmultiply(r2,prices,columns,columns);

 

   fscanf(d,"%s\n",label);

   //make sure there aren't two training data file

   if (strncmp(label,"data",4) != 0) {

       printf("error\n");

       exit(0);

   }

   fscanf(d,"%d\n",&columns);

   fscanf(d,"%d\n",&rows);

   columns++; //there will me k+1 columns

 

   data = (double **) malloc(rows * sizeof(double *));

   for (i = 0; i < rows; i++) {

       data[i] = (double *) malloc(columns * sizeof(double));

       data[i][0] = 1; //make the first column all 1s

   }

   for (i = 0; i < rows; i++) {

       for (j = 1; j < columns; j++) {

           fscanf(d,"%lf ",&data[i][j]);

       }

       fscanf(d,"\n");

   }

   

   r3 = vmultiply(data,weights,rows,columns);

   for (i = 0; i < rows; i++) {

       printf("%.0f\n",r3[i]);

   }

   return 0;

}

double ** transpose(double ** m,int rows,int columns) {

 

   double ** t = (double **) malloc(columns * sizeof(double *));

   int i,j;

   for (i = 0; i < columns; i++) {

       t[i] = (double *) malloc(rows * sizeof(double));

   }

   for (i = 0; i < columns; i++) {

       for (j = 0; j < rows; j++) {

           t[i][j] = m[j][i];

       }

   }

   return t;

}

double ** multiply(double ** m1,double ** m2,int rows1,int rows2,int columns) {

   double ** t = (double **) malloc(rows1 * sizeof(double *));

   int i,j,k;

   for (i = 0; i < rows1; i++) {

       t[i] = (double *) malloc(columns * sizeof(double));

       //make every element 0 to prevent error

       for (j = 0; j < columns; j++) {

           t[i][j] = 0;

       }

   }

   for (i = 0; i < rows1; i++) {

       for (j = 0; j < columns; j++) {

           for (k = 0; k < rows2; k++) {

               t[i][j] += m1[i][k] * m2[k][j];

           }

       }

   }

   return t;

}

double * vmultiply(double ** m,double * v,int rows,int columns) {

   double * t = (double *) malloc(rows * sizeof(double));

   //make sure every element is preset to 0

   int i,j;

   for (i = 0; i < rows; i++) {

       t[i] = 0;

   }

   for (i = 0; i < rows; i++) {

       for (j = 0; j < columns; j++) {

           t[i] += m[i][j] * v[j];

       }

   }

   return t;

}

double ** inverse(double ** m,int size) {

 

   double ** id = (double **) malloc(size * sizeof(double *));

   int i,j,k;

   for (i = 0; i < size; i++) {

       id[i] = (double *) malloc(size * sizeof(double));

       for (j = 0; j < size; j++) {

           if (i == j) {

               id[i][j] = 1;

           } else {

               id[i][j] = 0;

           }

       }

   }

   for (int i = 0; i < size; i++) {

       double rec; //reciprocal value of the pivot

     

       if (m[i][i] != 1) {

           rec = 1/m[i][i];

           

           for (j = 0; j < size; j++) {

               m[i][j] *= rec;

               id[i][j] *= rec; //make the adjustment to the identity matrix

             

               if (m[i][j] == -0) m[i][j] = 0;

               if (id[i][j] == -0) id[i][j] = 0;

           }

       }

     

       for (k = i+1; k < size; k++) {

           double f; //factor of pivot value

           if (m[k][i] != 0) {

               f = m[k][i] * -1;

         

               int l;

               for (l = 0; l < size; l++) {

                   m[k][l] += (f*m[i][l]);

                   id[k][l] += (f*id[i][l]);

                 

                   if (m[k][l] == -0) m[k][l] = 0;

                   if (id[k][l] == -0) id[k][l] = 0;

               }

           }

       }

   }

  for (i = size-1; i >= 0; i--) {

      double rec;

      if (m[i][i] != 1) {

          rec = 1/m[i][i];

          for (j = 0; j < size; j++) {

              m[i][i] *= rec;

              id[i][i] *= rec;

              if (m[i][j] == -0) m[i][j] = 0;

              if (id[i][j] == -0) id[i][j] = 0;

          }

      }

      for (k = i-1; k >= 0; k--) {

           double f;

           if (m[k][i] != 0) {

               f = m[k][i] * -1;

           

               int l;

               for (l = 0; l < size; l++) {

                   m[k][l] += (f*m[i][l]);

                   id[k][l] += (f*id[i][l]);

                 

                   if (m[k][l] == -0) m[k][l] = 0;

                   if (id[k][l] == -0) id[k][l] = 0;

               }

           }

      }

  }

 

  return id;

}

You might be interested in
Which task is a part of the analysis phase of the SDLC
eduard
Following are the seven phases of the SDLC:Planning (1), Systems Analysis (2), Systems Design (3), Development (4), Testing (5), Implementation (6) and Maintenance (7)
8 0
3 years ago
Read 2 more answers
Authorized agent Confidentiality Integrity Encryption 6:53 PM ______ means that only people with the right permission can access
mojhsa [17]

Answer:

The answer is "Confidentiality"

Explanation:

Confidentiality alludes to shielding data from being gotten to by unapproved parties. All in all, solitary the individuals who are approved to do so can access delicate information. Imagine your bank records, You ought to have the option to get to them obviously, and representatives at the bank who are assisting you with an exchange ought to have the option to get to them, yet nobody else ought to. An inability to keep up Confidentiality implies that somebody who shouldn't have access has figured out how to get it, through deliberate act or coincidentally. Such a disappointment of Confidentiality, normally known as a breach  can't be helped. When the secret has been uncovered, it is highly unlikely to un-uncover it.

Assuming your bank records are posted on a public site, everybody can realize your bank account number, balance, and so forth, and that data can't be eradicated from their brains, papers, PCs, and different spots. Virtually all the significant security occurrences reported in the media today include loss of Confidentiality.

Thus, in summary, a breach of Confidentiality implies that somebody accesses data who shouldn't be permitted to.

6 0
3 years ago
Whats worth more in adopt me- A Mega Owl or a Mega Frost Dragon?
serg [7]

Answer:

I think mega frost dragon i d k

Explanation:

6 0
3 years ago
Read 2 more answers
Assume a 15 cm diameter wafer has a cost of 12, contains 84 dies, and has0.020 defects /cm2Assume a 20 cm diameter wafer has a c
Vitek1552 [10]

Answer:

1. yield_1=0.959 and yield_2=0.909

2. Cost_1=0.148 and Cost_2=0.165

3. New area per die=1.912 cm^2 and yield_1=0.957

   New area per die=2.85 cm^2  and yield_2=0.905

4. defects=0.042 per cm^2 and defects=0.026 per cm^2

Explanation:

1. Find the yield for both wafers.

yield= 1/(1+(defects per unit area*dies per unit area/2))^2

Wafer 1:

Radius=Diameter/2=15/2=7.5 cm

Total Area=pi*r^2=pi(7.5)^2=176.71 cm^2

Area per die= 176.71/84=2.1 cm^2

yield_1= 1/(1+(0.020*2.1/2))^2

yield_1=1/1.04244=0.959

Wafer 2:

Radius=Diameter/2=20/2=10 cm

Total Area=pi*r^2=pi(10)^2=314.159 cm^2

Area per die= 314.159/100=3.14 cm^2

yield_2= 1/(1+(0.031*3.14/2))^2

yield_2=1/1.0997=0.909

2. Find the cost per die for both wafers.

Cost per die= cost per wafer/Dies per wafer*yield

Wafer 1:

Cost_1=12/84*0.959=0.148

Wafer 2:

Cost_2=15/100*0.909=0.165

3. If the number of dies per wafer is increased by 10% and the defects per area unit increases by 15%, find the die area and yield.

Wafer 1:

There is a 10% increase in the number of dies

10% of 84 =8.4

New number of dies=84.4+8=92.4

There is a 15% increase in the defects per cm^2

15% of 0.020=0.003

New defects per area= 0.020 + 0.003=0.023 defects per cm^2

New area per die= 176.71/92.4=1.912 cm^2

yield_1= 1/(1+(0.023*1.912/2))^2=0.957

Wafer 2:

There is a 10% increase in the number of dies

10% of 100=10

New number of dies=100+10=110

There is a 15% increase in the defects per cm^2

15% of 0.031=0.0046

New defects per area= 0.031 + 0.00465=0.0356 defects per cm^2

New area per die= 314.159/110=2.85 cm^2

yield_2= 1/(1+(0.0356*2.85/2))^2=0.905

4. Assume a fabrication process improves the yield from 0.92 to 0.95. Find the defects per area unit for each version of the technology given a die area of

Assuming a die area of 2cm^2

We have to find the defects per unit area for a yield of 0.92 and 0.95

Rearranging the yield equation,

yield= 1/(1+(defects*die area/2))^2

defects=2*(1/sqrt(yield) - 1)/die area

For 0.92 technology

defects=2*(1/sqrt(0.92) - 1)/2

defects=0.042 per cm^2

For 0.95 technology

defects=2*(1/sqrt(0.95) - 1)/2

defects=0.026 per cm^2

6 0
4 years ago
Ventaja que implica usar funciones en las hojas de calculo
lys-0071 [83]

Answer:

Explanationeeigrtghh:

baba booey

8 0
3 years ago
Other questions:
  • Which type of system must you connect to and use to make changes to Active Directory?
    15·1 answer
  • • Suppose Host A wants to send a large file to Host B. The path from Host A to Host B has three links, of rates R1= 500 kbps, R2
    15·1 answer
  • What are the basic tools for coding HTML manually?
    9·2 answers
  • What is one of the most effective security tools available for protecting users from external threats?
    15·1 answer
  • 2. What is an inanimate object? (1.0 points)
    14·1 answer
  • Need help with this
    13·1 answer
  • Even if you cannot afford it you should donate at least 5 of your earnings to charity true or false
    8·1 answer
  • Anyone can help me please ?
    7·1 answer
  • X274: Recursion Programming Exercise: Cannonballs Spherical objects, such as cannonballs, can be stacked to form a pyramid with
    7·1 answer
  • What is this line called that appears and disappears in the search box<br><br> WILL MARK BRAINLIEST
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!