Monthly Archives: December 2016

Javascript is awesome

Javascript logo.

I’m very excited about studying Javascript on the mission of expand my knowledges at front-end. The principal goal is use Javascript at my Java back-end projects.

So, two things I really liked on javascript so far is:

  1. template string;
  2. spread operator.

The first concept lets a array be used as params of methods, on a very easy and functional way.

The second one helps on format messages that uses dynamics values, as variables. We can just reference the value inside a string pattern, marked with the ` character.

See the example…

Continue reading

Machine Learning – Classification

How it works?

Tthere’s a input x, like sentence from review, a classified MODEL that generates the output, y. The predicted class, like positive or negative reviews.

Applications:

Multiclass Classifier: input (x) webpages and classifiers (y) like education, sport, health, IT and so on.

Spam filtering: by model classification of email input variables like text of email, ip, sender, etc. To output of classifying into not spam or spam.

Image classification: predictions through analysis of pixel images.

Personalized medical diagnosis: input of indicators like temperature, x-ray analysis, medical tests, for a disease classifier model, that predicts healthy, cold, flu, pneumonia etc.

And the last, the application for reading minds, with brain images that, applied to a model classifier it is possible to discover which image is seeing by the person.

Lambdas Oracle MOOC

Java 8 Lambda

Section 1

– Need changes to Java to simplify parallel coding.
– Lambda expressions simplify how to pass behavior as a parameter.

-Show the differences through Java basic code, inner classes and lambdas.

Non-functional (imperative) programming style versus functional.

Problem: external iteration.
After: more functional with inner classes;
And then: lambda approach, more concise, less code (error-prone), client logic is stateless, thread-safe.

The lambda expression provides the implementation of the abstract method. The type is the abstract method.

@FunctionalInterface -> Functional Interface = an interface with one abstract method; default doesn’t count. The equals also doesn’t count in therms of abstract method.

Variable assignment: Callable c = () -> process();

Method parameter: mew Thread(() -> process()).start();

Lambda expressions can be used anywhere the type is a functional interface.

– A functional interface has only one abstract method.

The lambda expression provides the implementation of the single abstract method of the functional interface.

java.util.function Package

Consumer<T>

Operation that takes a single value and return no result: String s -> System.out.println(s) .

Example: String s -> System.out.println(s);

BiConsumer<T,U>

Takes two values and returns no result.

Example: (k,v) -> System.out.println(“key: ” + k + “, value: ” + v);

Supplier

The opposite of a Consumer. Doesn’t take any parameter and returns a value.

Example: ( ) -> createLogMessage();

Function<T,R>

Takes one argument, do something and returns a result.

Example: Student s -> s.getName();

BiFunction<T,U,R>

Takes two arguments and returns a result.

Example: (String name, Student s) -> new Teacher(name, student);

UnaryOperator<T>

Kind function: single argument and result of the same type.

  • T apply(T a)

Example: String s -> s.toLowerCase();

BinaryOperartor<T>

Specialised form of BiFunction: two arguments and a result, all of the same type.

  • T apply(T a, T b)

Example: (String x, String y) -> { if (x.length() > y.length()) return x; return y; }

Predicate

A boolean valued function of one argument:

Example: Student s -> s.graduationYear() == 2011

BiPredicate

Takes two arguments

Example: (Student s, int minGrade) -> s.grade <= minGrade

Method and constructor references

FileFilter x = (File f) -> f.canRead();

FileFilter x = File::canRead;

External variables

Final or effective final.

Link to the on line free Oracle course.