Skip to content

Latest commit

 

History

History

Digital-Assignment

Digital Assignment - 1

Develop Java Programs implementing 10 new concepts/features/Topics (not in our syllabus).

Final uploaded file

Sending Email in Java through Gmail Server

  • Code
  • Source
  • .jar files
  • Steps:
    1. Get the session object: The javax.mail.Session class provides two methods to get the object of session, Session.getDefaultInstance() method and Session.getInstance() method.
    2. Compose the message: The javax.mail.Message class provides methods to compose the message. But it is an abstract class so its subclass javax.mail.internet.MimeMessage class is mostly used. To create the message, you need to pass session object in MimeMessage class constructor.
    3. Resolving Authentication failure: Click on this link and click on turn on radio button to allow users to send mail from unknown location.

Language Detection using OpenNLP

  • Code - LanguageDetectorMain.java, LanguageMapper.java
  • Source
  • .jar files
  • The Apache OpenNLP library is a machine learning based toolkit for the processing of natural language text. It supports the most common NLP tasks, such as language detection, tokenization, sentence segmentation, part-of-speech tagging, named entity extraction, chunking, parsing and coreference resolution.
  • This model is trained for and works well with longer texts that have at least 2 sentences or more from the same language.

Commons Math

The Apache Commons Mathematics Library. Jar files here - .jar files

Analysis

  • Code
  • Analysis related functions and algorithms can be found in org.apache.commons.math3.analysis.
  • Root Finding:
    • A root is a value where a function has the value of 0. Commons-Math includes implementation of several root-finding algorithms.

    • Here, we try to find the root of v -> (v * v) – 2 :

      UnivariateFunction function = v -> Math.pow(v, 2) - 2;
      UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-8, 5);
      double c = solver.solve(100, function, -10.0, 10.0, 0);
    • First, we start by defining the function, then we define the solver, and we set the desired accuracy. Finally, we call the solve() API.

    • The root-finding operation will be performed using several iterations, so it’s a matter of finding a compromise between execution time and accuracy.

  • Calculating integrals:
    • The integration works almost like root finding:
      UnivariateFunction function = v -> v;
      UnivariateIntegrator integrator = new SimpsonIntegrator(1.0e-12, 1.0e-8, 1, 32);
      double i = integrator.integrate(100, function, 0, 10);
      
    • We start by defining a function, we choose an integrator among the available integration solutions existing, we set the desired accuracy, and finally, we integrate.
  • Linear Algebra:
    • If we have a linear system of equations under the form AX = B where A is a matrix of real numbers, and B a vector of real numbers – Commons Math provides structures to represent both the matrix and the vector, and also provide solvers to find the value of X:

      RealMatrix a = new Array2DRowRealMatrix(new double[][] { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } },false);
      RealVector b = new ArrayRealVector(new double[] { 1, -2, 1 }, false); 
      DecompositionSolver solver = new LUDecomposition(a).getSolver();
      RealVector solution = solver.solve(b);
    • The case is pretty straightforward: we define a matrix a from an array of array of doubles, and a vector b from an array of a vector.

    • Then, we create an LUDecomposition which provides a solver for equations under the form AX = B. As its name states it, LUDecomposition relies on the LU decomposition, and thus works only with square matrices.

    • For other matrices, different solvers exist, usually solving the equation using the least square method.

Statistics and Probrabilities

  • Code

  • The package org.apache.commons.math3.stat provides several tools for statistical computations.

  • In core Java, Math.random() can be used for generating random values, but these values are uniformly distributed between 0 and 1.

  • Sometimes, we want to produce a random value using a more complex distribution. For this, we can use the framework provided by org.apache.commons.math3.distribution.

  • Here is how to generate random values according to the normal distribution with the mean of 10 and the standard deviation of 3:

  • NormalDistribution normalDistribution = new NormalDistribution(10, 3);
    double randomValue = normalDistribution.sample();
  • Or we can obtain the probability P(X = x) of getting a value for discrete distributions, or the cumulative probability P(X <= x) for continuous distributions.

Tokenization using Apache OpenNLP

Weka

  • Weka is a collection of machine learning algorithms for data mining tasks. It contains tools for data preparation, classification, regression, clustering, association rules mining, and visualization.
  • .jar files

K-means

Classification

JDMP

  • The Java Data Mining Package (JDMP) is an open source Java library for data analysis and machine learning. It facilitates the access to data sources and machine learning algorithms (e.g. clustering, regression, classification, graphical models, optimization) and provides visualization modules. JDMP provides a number of algorithms and tools, but also interfaces to other machine learning and data mining packages (Weka, LibLinear, Elasticsearch, LibSVM, Mallet, Lucene, Octave).
  • .jar file
  • .jar file
  • Linear Regression Classification
  • Naive Bayes Classification