Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package modela;
- import java.util.Vector;
- /**
- *
- * @author HP
- */
- public class ModelA {
- /**
- * @param args the command line arguments
- */
- public static final Double[] z0 = {
- -1.0,-1.0,-1.0,-1.0,-1.0,
- -1.0, 1.0, 1.0, 1.0,-1.0,
- -1.0, 1.0,-1.0, 1.0,-1.0,
- -1.0, 1.0, 1.0, 1.0,-1.0,
- -1.0,-1.0,-1.0,-1.0,-1.0 //z1
- };
- public static final Double[] z1 = {
- -1.0,-1.0,-1.0,-1.0,-1.0,
- -1.0, 1.0, 1.0,-1.0,-1.0,
- -1.0,-1.0, 1.0,-1.0,-1.0,
- -1.0,-1.0, 1.0,-1.0,-1.0,
- -1.0,-1.0,-1.0,-1.0,-1.0
- };
- public static final Double[] zprim0 = {
- -1.0, 1.0, 1.0, 1.0,-1.0,
- -1.0, 1.0,-1.0, 1.0,-1.0,
- -1.0, 1.0,-1.0, 1.0,-1.0,
- -1.0, 1.0, 1.0, 1.0,-1.0,
- -1.0,-1.0,-1.0,-1.0,-1.0 //z1
- };
- public static final Double[] zprim1 = {
- -1.0,-1.0, 1.0,-1.0,-1.0,
- -1.0,-1.0, 1.0,-1.0,-1.0,
- -1.0,-1.0, 1.0,-1.0,-1.0,
- -1.0,-1.0, 1.0,-1.0,-1.0,
- -1.0,-1.0, 1.0,-1.0,-1.0
- };
- static public Vector<Double> fill(Double[] a)
- {
- Vector<Double> wektor = new Vector<Double>();
- for(int i = 0;i<25;i++)
- {
- wektor.add(a[i]);
- }
- return wektor;
- }
- static public Vector<Vector<Double>> fillW( Vector<Double> z0, Vector<Double> z1)
- {
- Vector<Vector<Double>> wVector = new Vector<Vector<Double>>();
- Vector<Double> w = new Vector<Double>();
- Vector<Double> temp = new Vector<Double>();
- for(int i = 0; i<25;i++)
- {
- for(int j=0;j<25;j++)
- {
- w.add(1.0/25.0 * (z0.get(i)*z0.get(j) + z1.get(i)*z1.get(j)));
- }
- wVector.add(w);
- w = new Vector<Double>();
- }
- return wVector;
- }
- static public Vector<Double> F(Vector<Vector<Double>> w,Vector<Double> z)
- {
- Vector<Double> u = new Vector<Double>();
- double value ;
- //System.out.println(z);
- for(int i =0; i<25;i++)
- {
- value = 0.0;
- for(int j = 0;j<25;j++)
- {
- value+=w.get(i).get(j) * z.get(j);
- }
- u.add(value);
- }
- u = sgn(u);
- return u;
- }
- static final Vector<Double> sgn (Vector<Double> u)
- {
- for (int i=0; i<25; i++) {
- if(u.get(i) >= 0.0) {
- u.set(i, 1.0);
- } else {
- u.set(i, -1.0);
- }
- }
- return u;
- }
- public static void interfejs(Vector<Double> u)
- {
- for (int i=0; i<25; i++) {
- if (u.get(i) == -1.0) {
- System.out.print(" ");
- } else {
- System.out.print(" * ");
- }
- if (i%5 == 4) {
- System.out.println("\n");
- }
- }
- }
- public static void main(String[] args) {
- // TODO code application logic here
- Vector<Double> VecZ0, VecZ1, VecZ0prim, VecZ1prim, result;
- Vector<Vector<Double>> Vec, Vecprim = new Vector<Vector<Double>>();
- VecZ0 = fill(z0);
- VecZ1 = fill(z1);
- Vec = fillW(VecZ0,VecZ1);
- //System.out.println(VecZ0 + "\n" + VecZ1 + "\n" );
- System.out.println("Dla z0");
- result = F(Vec, VecZ0);
- interfejs(result);
- // System.out.println("\n");
- System.out.println("Dla z1");
- result = F(Vec, VecZ1);
- interfejs(result);
- System.out.println("Dla wartości zaburzonych");
- VecZ0prim = fill(zprim0);
- VecZ1prim = fill(zprim1);
- Vecprim = fillW(VecZ0prim,VecZ1prim);
- result = F(Vecprim, VecZ0prim);
- interfejs(result);
- result = F(Vecprim, VecZ1prim);
- interfejs(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement