All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.empty3.feature20220726.Clusters Maven / Gradle / Ivy

Go to download

3D rendering engine. Plus modelling. Expected glsl textures 3d and 2d rendering3D primitives, and a lot of scenes' samples to test.+ Game Jogl reworked, Calculator (numbers and vectors). Java code parser implementation starts (<=1.2)

The newest version!
/*
 *
 *  * Copyright (c) 2024. Manuel Daniel Dahmen
 *  *
 *  *
 *  *    Copyright 2024 Manuel Daniel Dahmen
 *  *
 *  *    Licensed under the Apache License, Version 2.0 (the "License");
 *  *    you may not use this file except in compliance with the License.
 *  *    You may obtain a copy of the License at
 *  *
 *  *        http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *    Unless required by applicable law or agreed to in writing, software
 *  *    distributed under the License is distributed on an "AS IS" BASIS,
 *  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *    See the License for the specific language governing permissions and
 *  *    limitations under the License.
 *
 *
 */

/*
DBSCAN(D, eps, MinPts)
   C = 0
   pour chaque point P non visité des données D
      marquer P comme visité
      PtsVoisins = epsilonVoisinage(D, P, eps)
      si tailleDe(PtsVoisins) < MinPts
         marquer P comme BRUIT
      sinon
         C++
         etendreCluster(D, P, PtsVoisins, C, eps, MinPts)
          
etendreCluster(D, P, PtsVoisins, C, eps, MinPts)
   ajouter P au cluster C
   pour chaque point P' de PtsVoisins 
      si P' n'a pas été visité
         marquer P' comme visité
         PtsVoisins' = epsilonVoisinage(D, P', eps)
         si tailleDe(PtsVoisins') >= MinPts
            PtsVoisins = PtsVoisins U PtsVoisins'
      si P' n'est membre d'aucun cluster
         ajouter P' au cluster C
          
epsilonVoisinage(D, P, eps)
 */
package one.empty3.feature20220726;

import one.empty3.io.ProcessFile;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.io.File;

public class Clusters extends ProcessFile {
    public boolean process(File in, File out) {
        return false;

    }

    public static List Data;
    public static List Clusters;
    public static List Pvisited;
    public static List clustered;
    public static List neighborpts;
    public static List neighbors;
    public static List noise;


    public static void read(int String) {

        String[] values;
        //System.out.println("Working Directory = " +
        // System.getProperty("user.dir"));

        Data = new ArrayList();
        Pvisited = new ArrayList();
        Double ve;

        try {
            BufferedReader in = new BufferedReader(new FileReader("wholesale.csv"));
            String line;
            Vector v = null;
            int j = 0;
            while ((line = in.readLine()) != null) {
                values = line.split(",");
                v = new Vector();
                for (int i = 0; i < values.length; i++) {
                    ve = Double.parseDouble(values[i]);

                    v.add(ve);

                }
                Data.add(v);
                //System.out.println(Data);
                Pvisited.add(false);
                //System.out.println(Pvisited.get(j));
                v = null;
                j++;
            }

            in.close();

        } catch (IOException ioException) {
        }
    }

    public static void DBSCAN(int esp, int minPts) {
        int c = 0;
        //System.out.println(c);
        Clusters = new ArrayList();
        neighborpts = new ArrayList();
        for (int i = 0; i < Data.size(); i++) {
            neighborpts.add(null);
        }
        noise = new ArrayList();
        for (int i = 0; i < Data.size(); i++) {
            //System.out.println("The size of the file is: "+ Data.size());
            if (!Pvisited.get(i)) {
                Pvisited.set(i, true);
                neighborpts.set(i, regionQuery(Data.get(i), esp));
                //System.out.println(neighborpts);
                int size = neighborpts.size();
                //System.out.println(minPts);
                if (size < minPts)
                    //System.out.println(noise);
                    noise.add(i);
                    //System.out.println(noise.get(i));
                else {
                    //System.out.println("HEy");
                    Clusters.addAll(Data.get(i));
                    //System.out.println(c);
                    c++;
                    //System.out.println("This is c" + c);
//            Clusters C = new Clusters(c);
//            C.setPoint(Data.get(c));
//            Clusters.add(C);
                    //System.out.println(size);
                    //C.printC().toString();//System.out.print(C.printC());
                    for (int j = 0; j < size; j++) {
                        //if P' is not visited
                        if (!Pvisited.get(neighborpts.indexOf(j))) {
                            Pvisited.set(j, true);
                            neighbors.add(regionQuery((Vector) neighborpts.get(j), esp));
                            //System.out.println(neighbors);
                            int nSize = neighbors.size();
                            //System.out.println(nSize);
                            if (nSize >= minPts) {
                                neighborpts.add(neighbors);
                            }
                        }
                        // if P' is not yet a member of any cluster
                        // add P' to cluster c
                        if (!clustered.get(neighborpts.indexOf(j))) {
                            int x = (int) neighborpts.get(j);
                            Clusters f = Clusters.get(c);
                            ((List) f).add(x);
                        }
                    }
                }
            }
        }//end of the main for loop
    }


    public static double ecluediean(Vector center, Vector L) {
        Double result = (double) 0;
        for (int i = 0; i < center.size(); i++) {
            result += Math.pow(((double) center.get(i)) - (double) (L.get(i)), 2);
        }

        return Math.sqrt(result);
    }

    public static List regionQuery(Vector p, int eps) {
        List n = new ArrayList();
        for (int i = 0; i < Data.size(); i++) {
            n.add(null);
        }
        double dis = 0;
        for (int i = 0; i < Data.size(); i++) {
            dis = ecluediean(p, Data.get(i));

            if (dis <= eps) {

                n.set(i, Data.get(i));
            }
        }
        //System.out.println(n);
        return n;
    }

    public static void main(String[] args) {
        int N = 3;
        read(1);

        DBSCAN(3, 5);


        //System.out.println(((List) Clusters.get(0)).get(1));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy