-

- -

Wednesday, February 24, 2021

Code Igniter 3 REST Controller Project With Sqlite



1. Startup Project

This project is extended from the original tutorial at :

https://erthru.medium.com/membuat-restful-api-menggunakan-framework-codeigniter-3-f350755b1274
and
https://erthru.medium.com/membuat-restful-api-menggunakan-framework-codeigniter-3-part-2-163cadb32e3a

The author has provided a completed project codes at:
https://github.com/erthru/restCI
or
https://drive.google.com/file/d/1tYrLlnPb4Gc-9769LyoLOcYcVKf2tYl4/view?usp=sharing




2. Download codes

Download the code from the source at Step 1 above.




3. Upload codes

Upload the zip file to your server, extract the content and rename the folder as "restci".




4. Edit database configuration

Go into restci/application/config/ and edit the file database.php as follows:




5. Create Database

note: it is recommended to use DB Browser application to create the database. The application can be downloaded from https://sqlitebrowser.org/dl/




6. Test Web Request

You should get a json output that shows no record in the database.




7. Test POST Request

Use a REST Client like POSTMAN to send POST Request according to the following settings:




8. You should get a success response as follows:




9.Repeat Step 7

go to the url {{your serverpath}}/restci/index.php/person
Now you get the following json output:
{"status":200,"error":false,"person":[{"id":1,"name":"suprianto","address":"jln testing","phone":123}]}




10.Optional

If you want to hide the index.php string in the url, you can put .htaccess file in the restci folder. Put the following codes into the file. This requires Apache mod_rewrite enabled.

File: restci/.htaccess

Now you can use the following url {{your serverpath}}//restci/person


11.Appendix

File: restci/application/controllers/TestApi.php

Sql Command: Person

File: restci/application/models/PersonM.php

Friday, February 19, 2021

Machine Learning In JavaScript

 .

Machine Learning (ML)

Machine Learning is often considered equivalent with Artifical Intelligence.

This is not correct. Machine learning is a subset of Artificial Intelligence.

Machine Learning is a disipline of AI that uses data to perform supervised or unsupervised machine training.

What is Machine Learning?

ML systems combines Input to produce Predictions.

Key terminologies are:

  • Labels
  • Features
  • Models
  • Training
  • Inference
  • Functions

Machine Learning Labels

In Machine Learning terminology, the label is the thing we want to predict.

It is like the y in a linear graph:

y = ax + b


Machine Learning Features

In Machine Learning terminology, the features are the input.

They are like the x values in a linear graph:

y = ax + b


Machine Learning Models

Model defines the relationship between the label (y) and the features (x).

There are three phases in the life of a model:

  • Data Collection
  • Training
  • Inference

Data Collection

Machine Learning can teach a computer to solve many questions like:

  • Is this cancer?
  • Is this a banana?

Before Machine Learning can start, you need to collect some data.

If you want to predict house prices, you need to collect some information about house prices.


Machine Learning Training

The goal of training is to create a model that can answer our question. Like what is the expected price for a house?


Machine Learning Inference

Inference is when the trained model is used to infer (predict) values using live data. Like putting the model into production.


Using a Linear Regression Function

This Model predicts prices using a linear regression function:

Prices

Example

# Name the Axis
plt.title('House Prices vs Size')
plt.xlabel('Square Meters')
plt.ylabel('Price in Millions')

# Set x and y values
x = np.array([50,60,70,80,90,100,110,120,130,140,150,160])
y = np.array([7,8,8,9,9,9,9,10,11,14,14,15])

# Call Linear Regression Function
slope, intercept, r, p, std_err = stats.linregress(x, y)

# Plot Data
plt.scatter(x, y)
plt.plot(x, slope * x + intercept)
plt.show()
Try it Yourself »

In the example above, the slope and intercept is calculated by a function called linregress.

From Previous Chapter

A linear relationship is written as y = ax + b

Where:

  • y is the price we want to predict
  • a is the slope of the line
  • x are the input values
  • b is the intercept

With Machine Learning

With ML, a linear relationship is written as y = b + wx

Where:

  • y is the label we want to predict
  • w is the weight (the slope)
  • x are the features (input values)
  • b is the intercept

Sometimes there can be many features (input values) with different weights:

y = b + w1x1 + w2x2 + w3x3 + w4x4


.

https://web.archive.org/web/20210220012931/https://www.w3schools.com/ai/ai_machine_learning.asp

.


Artificial Intelligence In JavaScript

.

Artificial Intelligence

AI in JavaScript

These days, several JavaScript AI framework are emerging.

JavaScript frameworks make it possible to execute AI tasks in the browser.

AI and JavaScript

Artificial Intelligence has changed the science of image processing, computer vision, and natural language applications.

Thanks to new AI libraries, JavaScript developers can now build machine learning and deep learning applications without Python or R. This way JavaScript can help developers to bring AI to the browser and to the web.


Is JavaScript Good for AI?

Most AI applications these days use R or Python.

But JavaScript has a great future as an AI language, and it even has a some advantages:

  • JS is better known. All developers can use it.
  • Security is built in. JS cannot access your files.
  • JS is faster than Python.
  • Modern JS compiles into machine code.
  • Modern JS can use hardware acceleration.

WebGL API

WebGL is a JavaScript API for rendering 2d and 3D graphics in any browser.

WebGL can run on both integrated and stanalone graphic cards in any PC.

WebGL brings 3D graphics to the web browser. Major browser vendors Apple (Safari), Google (Chrome), Microsoft (Edge), and Mozilla (Firefox) are members of the WebGL Working Group.

WebGL 1.0 was released in March 2011.

WebGL 2.0 was released in January 2017.

JellyFish


TensorFlow Playground

TensorFlow Playground is a web application written in d3.js.

With TensorFlow Playground you can learn about Neural Networks (NN) without math.

In your own Web Browser you can create a Neural Network and see the result.


Plotting in JavaScript

01234567891516171819

Plotting provided by: Plotly

.

https://web.archive.org/web/20210220012909/https://www.w3schools.com/ai/ai_javascript.asp

.