Sunday, 11 November 2018

Start Learning AI

Introduction To Artificial Intelligence 

Artificial Intelligence is a way of making a computer, a computer-controlled robot, or a software think intelligently, in the similar manner the intelligent humans think.

Applications  of AI:
AI can be implemented in various fields, such as in a self driving car, Cancer Prediction, Robot as Lecturer  etc.

Two Subsets of AI:

AI subsets
Artificial Intelligence


  1. Machine Learning 
  2. Deep Learning

  1. Machine Learning  :

    Machine Learning is a subset of Artificial Intelligence.
    ML systems learn how to combine input to produce useful predictions on never-before-seen data.
    In Machine Learning , We train a model using a large set of labeled data, later on this model is used to test a set of test data i.e unlabeled data. Then accuracy is calculated that how accurate  the prediction is.

    Suppose that we need an AI to check whether this object is dog or not, then we provide various sets of  sample inputs during the training of our model.
    inputs consist of feature and label
     Dog can be identified by the way they: speak, run, height, eyes, tail etc.
    Here label is DOG and Features are sound, speed, height, and eye.

    When we say labeled data it means that a large data set  that contains Feature and Label.
    So ML moves around mainly three terminologies:
     (i) Label  (ii) Feature (iii) Model

    (i) Label:

    A label is the thing we're predicting—the y variable in simple linear regression. The label could be the future price of wheat, the kind of animal shown in a picture, the meaning of an audio clip, or just about anything.  
     

    (ii) Feature:

    A feature is an input variable—the x variable in simple linear regression. A simple machine learning project might use a single feature, while a more sophisticated machine learning project could use millions of features, specified as:  x1, x2, ...., xn
     Feature could be a property possessed by that thing which is useful to identify that thing uniquely/partially.

    (iii) Model: 

    A model defines the relationship between features and label.

    • Training means creating or learning the model. That is, you show the model labeled examples and enable the model to gradually learn the relationships

      between features and label.
    • Inference means applying the trained model to unlabeled examples. That is, you use the trained model to make useful predictions (y'). 

     Labeled Example:  

    This example is an instance of training data. 
    {x, y} or      {Feature, Label}  

    In order to train our model, we fed a large set of such instances with features and labels. 

    Unlabeled Example:

    This example is an instance of testing data. 
    {x, ?}  or   {Feature, ?}
    Finally we get a trained model that takes the unlabeled test data and make predictions for each test data. 

    "Regression vs. classification"

    A regression model predicts continuous values. For example, regression models make predictions that answer questions like the following:
    • What is the value of a house in California?
    • What is the probability that a user will click on this ad?

    A classification model predicts discrete values. For example, classification models make    predictions that answer questions like the following:
    • Is a given email message spam or not spam?
    • Is this an image of a dog, a cat, or a hamster?   
       
      Model can learn using two approaches: Supervised Learning and Unsupervised Learning.

      " In supervised learning model is being trained under the supervision of input labeled data.But in unsupervised learning no hint is provided during the training of model. Model learns by its own."

       

      "Machine Learning changes the way you think about a problem. The focus shifts from a mathematical science to a natural science, running experiments and using statistics, not logic, to analyse its results." - Peter Norvig - Google Research Director

       

Friday, 9 November 2018

Private Facebook messages are being sold on the internet

  • People's private Facebook messages are being sold on the internet for anyone to read.
  • Tens of thousands of people's secret chats are being traded without their knowledge, according to a BBC report.
  • In all, at least 81,000 people's messages are being swapped online, the report claimed. Many of them came from Ukraine and Russia, but many more besides were from users in the UK, the US, Brazil and elsewhere.
Lock your profile down
Compromised accounts that were caught up in the hack are being sold for just $0.10 each, according to the report.
The leak does not appear to have come from Facebook itself, despite a series of data scandals. Instead, it appears to have been the consequence of malicious browser extensions, which install themselves onto people's computers and are then able to watch their activity and break into their account.
The hackers claimed to have access to 120 million accounts, but they appear to have been exaggeration the scale of the attack. However, the hackers showed some evidence of having the messages of some 81,000 people, a number of which were checked with account holders and confirmed to be genuine.
Facebook said it had contacted browser companies to ensure that the malicious extensions were no longer used. But it advised its users to check the extensions they have installed and remove any that might be malicious.
“Based on our investigation so far, we believe this information was obtained through malicious browser extensions installed off of Facebook,” Guy Rosen, Facebook's vice president of product management, said in a statement emailed to a number of outlets.
“We have contacted browser makers to ensure that known malicious extensions are no longer available to download in their stores and to share information that could help identify additional extensions that may be related,” Rosen said. “We have also contacted law enforcement and have worked with local authorities to remove the website that displayed information from Facebook accounts.”
“We encourage people to check the browser extensions they’ve installed and remove any that they don’t fully trust. As we continue to investigate, we will take action to secure people’s accounts as appropriate.”

Artificial intelligence technique can boost brain scans to predict Alzheimer early - details inside

The results showed that the algorithm was able to teach itself metabolic patterns that corresponded to Alzheimer's disease.

Artificial intelligence (AI) can help improve the ability of brain imaging techniques to predict Alzheimer's disease early, according to a study. Researchers from the University of California in San Francisco (UCSF) trained a deep learning algorithm on a special imaging technology known as 18-F-fluorodeoxyglucose positron emission tomography (FDG-PET).

They included more than 2,100 FDG-PET brain images from 1,002 patients and on an independent set of 40 imaging exams from 40 patients. The results showed that the algorithm was able to teach itself metabolic patterns that corresponded to Alzheimer's disease.

It also achieved 100 per cent sensitivity at detecting the disease an average of more than six years prior to the final diagnosis. "We were very pleased with the algorithm's performance. It was able to predict every single case that advanced to Alzheimer's disease," said Jae Ho Sohn, from UCSF's Radiology and Biomedical Imaging Department.

"If FDG-PET with AI can predict Alzheimer's disease this early, beta-amyloid plaque and tau protein PET imaging can possibly add another dimension of important predictive power," he added, in the paper detailed in the journal Radiology. While early diagnosis of Alzheimer's is extremely important for the treatment, it has proven to be challenging.

Although the cause behind the progressive brain disorder remains unconfimed yet, various research has linked the disease process to changes in metabolism, as shown by glucose uptake in certain regions of the brain.  These changes can be difficult to recognise.

"If we diagnose Alzheimer's disease when all the symptoms have manifested, the brain volume loss is so significant that it's too late to intervene," Sohn said.  "If we can detect it earlier, that's an opportunity for investigators to potentially find better ways to slow down or even halt the disease process," he noted.

Sohn explained that the algorithm could be a useful tool to complement the work of radiologists - especially in conjunction with other biochemical and imaging tests - in providing an opportunity for early therapeutic intervention.

Tuesday, 6 November 2018

Picasso Android Tutorial – Android Picasso Image Loader Library

Hello programmers, today we will be learning about picasso library for image downloading developed by sqaure.
  • Picasso one of the most popular library for image downloading.
  • It makes our wok very simple so its powerful library for image downloading.
  • It uses caching technique.
  • I have already published a post on Glide(similar to picasso) Image Downloading library for android.


Why Picasso library?

Its obvious that you will think why we should use picasso library.
If we use the traditional method of downloading the image from a url then we need to manage a lots of thing.
 And of course lines of code and development time will also increase.
 But if we will use a 3rd party library like picasso then we will achieve our goal in few lines of code.  So if we will not use a 3rd party library then  we would need
  1. Very large amount of code to be written
  2. We have to write another logic to implement caching.
  3. Caching is very important to make the application faster.
  4. We also have to deal with memory while writing the code.
  5. If any error occurs we need to handle that also.
  6. we will not focusing more on the application feature that is going to be developed. 
So, picasso will handle these all by default and overcome these all problems.

Adding Picasso Library to our Android Project

Adding picasso android library to your project is very easy.
Add the following line in the dependency block of your build.gradle file(app /module level).
I am assuming that you are using Android Studio.
After adding it just sync your project.

Loading Image from URL by Using Picasso Android Library

Loading image from URL by using Picasso Android Library is very simple and easy. The first thing we would need is an ImageView

Code for Loading Image with Picasso

It is very simple. We have to use the Picasso class.

 Picasso.get()  
 .load(IMAGE_URL)  
 .into(imageView);  


Placeholder and Error Handling

  • Because we are loading the image from internet.
  • the process would take some time depending on the internet speed. 
  • So it would be a good idea to display a image from the device while the image from URL is getting loaded.
  • One more situation could be when the image is not downloaded from the URL (when the URL given is wrong). 
  • In this case we should display an error image.
  • Both these things can be done very easily by using picasso.
  • See the following code snippet.

  Picasso.get()
   .load("YOUR IMAGE URL HERE")  
   .placeholder(Your Drawable Resource) // optional the image to display while the url image is downloading  
   .error(Your Drawable Resource) //this is also optional if some error has occurred in downloading the image                                  //this image would be displayed  
   .into(imageView);  

Re-sizing and Rotating

We can also resize and rotate the image very easily.


 Picasso.with(this)  
    .load("YOUR IMAGE URL HERE")      
    .placeholder(DRAWABLE RESOURCE)  // optional      
    .error(DRAWABLE RESOURCE)   // optional      
    .resize(width, height)            // optional      
    .rotate(degree)               // optional      
    .into(imageView);  


Using Picasso Android Library in Our Project

Now lets try the above codes in our Android Studio Project. So I will be creating a new Android Project.

  • Open Android Studio and create a new project.
  • I have created PicassoExample. 
  • First we have to add the Picasso Library. 
  • So open your build.gradle(app level) and add the following line inside dependency block and sync your project.
  • As we will load the image from a URL so we will also need internet permission. 
  • So open AndroidManifest.xml and add internet permission.
 <?xml version="1.0" encoding="utf-8"?>  
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:app="http://schemas.android.com/apk/res-auto"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:orientation="vertical"  
   android:layout_height="match_parent"  
   tools:context=".MainActivity">  
   <ImageView  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_centerInParent="true"  
     android:src="@mipmap/ic_launcher_round"  
     android:id="@+id/imageView"  
     />  
   <Button  
     android:layout_width="match_parent"  
     android:id="@+id/btn"  
     android:layout_below="@+id/imageView"  
     android:layout_centerHorizontal="true"  
     android:text="show image"  
     android:layout_margin="10dp"  
     android:layout_height="wrap_content" />  
 </RelativeLayout>  


  • Now come inside MainActivity.java and define your ImageView and a button.

MainActivity.java 

 package protector.video.com.picasoexample;  
 import android.os.Bundle;  
 import android.support.v7.app.AppCompatActivity;  
 import android.view.View;  
 import android.widget.Button;  
 import android.widget.ImageView;  
 import com.squareup.picasso.Picasso;  
 public class MainActivity extends AppCompatActivity {  
   private ImageView imageView;  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
     Button btn=findViewById(R.id.btn);  
     imageView=findViewById(R.id.imageView);  
     //setting click listener to the button
     btn.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View v) {  
         Picasso.get()  
             .load("https://avatars0.githubusercontent.com/u/1?v=4")  
             .placeholder(R.drawable.ic_image_black_24dp) // optional the image to display while the url image is downloading  
             .error(R.drawable.ic_error_black_24dp) //this is also optional if some error has occurred in downloading the image                 //this image would be displayed  
             .into(imageView);  
       }  
     });  
   }  
 }  
  • We need two images one for placeholder and one for error. I will be using the following images. Just save these and paste inside the drawable folder of your project.
  • Now we need a URL to an ImageFile. I have this URL https://avatars0.githubusercontent.com/u/1?v=4


Finally run your application. 
Picasso Android 
Happy coding......
Thank You

Monday, 5 November 2018

Glide - Image Download library for android

What is Glide?

  • Glide is an open source media management framework for Android.
  • Control media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface
  • Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs.
  • Glide includes a flexible API that allows developers to plug in to almost any network stack 
  • Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.

Glide Unique Features

  1. Animated GIF decoding : you can load GIF animation into ImageView.
  2. Supports Thumbnail
  3. Supports OkHttp and Volley library & retrofilt library
  4. Placeholder can be added before loading the original image.
  5. Any custom image can be shown if error occurs while loading the original image.

Alternatives of Glide 

  •  Picasso  

Why Image loader library? 

  • To show an image into ImageView from a url we need to download that image
  • downloading the complete image from remote location, handle network errors if occurs while downloading. 
  • Implement image caching.
To download an image one should do a lot of things.
This will increase the lines of code and of course development time.
So its better to use the library to reduce our work and focus more on the development idea.

Steps to use Glide?

step 1.

 Add dependency for Glide into app/build.gradle.
dependencies {

implementation 'com.github.bumptech.glide:glide:4.8.0
} 

Step 2.

 Add INTERNET permission in manifest file 

 <uses-permission android:name="android.permission.INTERNET" /> 

Step 3

 Add ImageView in you layout

Declare an ImageView in your layout to display image from remote server in it
 <ImageView  
   android:layout_width="wrap_content"  
   android:layout_height="wrap_content"  
   android:id="@+id/imageView">  
 </ImageView>

Step 4 

 Add ImageView in you layout


 Glide.with(this)  
     .load("IMAGE URL HERE")  
     .placeholder(R.drawable.placeholder)  
     .error(R.drawable.imagenotfound)  
     .into(imageView);



MainActivity.java

 public class MainActivity extends AppCompatActivity {  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
     final String url="https://avatars0.githubusercontent.com/u/1?v=4";  
     //Glide  
     Button btn=findViewById(R.id.btn);  
     final ImageView imageView=findViewById(R.id.img);  
     btn.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View v) {  
         Glide.with(MainActivity.this).load(url).into(imageView);  
       }  
     });  
   }  
 }  

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:app="http://schemas.android.com/apk/res-auto"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:orientation="vertical"  
   android:layout_height="match_parent"  
   tools:context=".MainActivity">  
   <ImageView  
     android:layout_width="wrap_content"  
     android:id="@+id/img"  
     android:src="@mipmap/ic_launcher"  
     android:layout_height="wrap_content" />  
   <Button  
     android:layout_width="wrap_content"  
     android:text="Download image and show"  
     android:id="@+id/btn"  
     android:layout_height="wrap_content" />  
 </LinearLayout>  

Tuesday, 26 September 2017

how to generate colorful output in c language

To generate colorful output on console in c language we are going to use a predefined function of c language that is textcolor().

Now ,in this post we will learn how to use this textcolor funtion to generate colorful output on console.

declaration of textcolor -

void textcolor(int color);

here we have to send the integral value of the corresponding  color that we want to use .

Color Numerical Value
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15

here are more colors than this. The colors available depend on the installed graphics drivers and current mode. Colors must be written in all Upper Case
because these colors are predefined macros.



                        note :we must use cpreintf function instead printf.

 #include<conio.h>  
 #include<stdio.h>  
 int main()  
 {  
         textcolor(RED);// the color is set to red  
         cprintf("I am Red");///the output will be in red color  
         textcolor(GREEN);// the color is set to green  
         cprintf("I am green");///the output will be in green color  
         textcolor(BLUE);// the color is set to blue  
         cprintf("I am blue");///the output will be in blue color  
         textcolor(CYAN);// the color is set to cyan  
         cprintf("I am Cyan");///the output will be in Cyan color  
         textcolor(YELLOW);// the color is set to yellow  
         cprintf("I am Yellow");///the output will be in yellow color  
        return 0;  
 }  

Friday, 1 September 2017

CONSTANT EXPRESSION REQUIRED-ERROR IN C PROGRAMMING

CONSTANT EXPRESSION REQUIRED-ERROR IN C PROGRAMMING 




The above program has error 'constant expression required' that means in between the [ ] constant yielding expression is needed or constant of type integer is needed.
While declaring an array the compiler must know how much memory will be reserved for how many elements of the array. So in C language at the time of declaration of an array we must provide a meaningful size of the array and the number of elements of any array can not be non- integral.
The size of the array must be integer because the number of elements can not be in fraction they can only be in integral numbers and cant be float or double.
               On the other context ,if we want to give the size of the array at the time of execution then we have to deal with a concept known as dynamic memory allocation and we need to use some predefined functions as calloc() ,malloc() and realloc().

How to implement Facebook audience network banner ad in android app using Android Studio

Its very simple to implement Facebook audience network banner ad in android app using Android Studio. We will complete it in 4 Steps. 1. ...