0% found this document useful (0 votes)
282 views

Welcome To Colaboratory - Colaboratory

Colaboratory (Colab) allows users to write and execute Python code in the browser using Google's servers. It requires no setup, provides free access to GPUs, and makes sharing notebooks easy. Colab notebooks combine code, rich text, and other media types and are stored in Google Drive for sharing or collaboration. Colab notebooks can be used for data science tasks like loading data, training models, and visualizing results using popular Python libraries.

Uploaded by

chairahmaulida
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
282 views

Welcome To Colaboratory - Colaboratory

Colaboratory (Colab) allows users to write and execute Python code in the browser using Google's servers. It requires no setup, provides free access to GPUs, and makes sharing notebooks easy. Colab notebooks combine code, rich text, and other media types and are stored in Google Drive for sharing or collaboration. Colab notebooks can be used for data science tasks like loading data, training models, and visualizing results using popular Python libraries.

Uploaded by

chairahmaulida
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

What is Colaboratory?

Colaboratory, or "Colab" for short, allows you to write and execute Python in your browser, with

Zero con guration required


Free access to GPUs
Easy sharing

Whether you're a student, a data scientist or an AI researcher, Colab can make your work easier. Watch Introduction to Colab to
learn more, or just get started below!

Getting started
The document you are reading is not a static web page, but an interactive environment called a Colab notebook that lets you wr
and execute code.

For example, here is a code cell with a short Python script that computes a value, stores it in a variable, and prints the result:

seconds_in_a_day = 24 * 60 * 60
seconds_in_a_day

86400

To execute the code in the above cell, select it with a click and then either press the play button to the left of the code, or use th
keyboard shortcut "Command/Ctrl+Enter". To edit the code, just click the cell and start editing.

Variables that you de ne in one cell can later be used in other cells:

seconds_in_a_week = 7 * seconds_in_a_day
seconds_in_a_week

Colab notebooks allow you to combine executable code and rich text in a single document, along with images, HTML, LaTeX a
more. When you create your own Colab notebooks, they are stored in your Google Drive account. You can easily share your Cola
notebooks with co-workers or friends, allowing them to comment on your notebooks or even edit them. To learn more, see Over
of Colab. To create a new Colab notebook you can use the File menu above, or use the following link: create a new Colab noteb

Colab notebooks are Jupyter notebooks that are hosted by Colab. To learn more about the Jupyter project, see jupyter.org.

Data science
With Colab you can harness the full power of popular Python libraries to analyze and visualize data. The code cell below uses n
to generate some random data, and uses matplotlib to visualize it. To edit the code, just click the cell and start editing.

import numpy as np
from matplotlib import pyplot as plt

ys = 200 + np.random.randn(100)
x = [x for x in range(len(ys))]

plt.plot(x, ys, '-')


plt.fill_between(x, ys, 195, where=(ys > 195), facecolor='g', alpha=0.6)

plt.title("Sample Visualization")
plt.show()

You can import your own data into Colab notebooks from your Google Drive account, including from spreadsheets, as well as fr
Github and many other sources. To learn more about importing data, and how Colab can be used for data science, see the links
below under Working with Data.

Machine learning
With Colab you can import an image dataset, train an image classi er on it, and evaluate the model, all in just a few lines of cod
Colab notebooks execute code on Google's cloud servers, meaning you can leverage the power of Google hardware, including G
and TPUs, regardless of the power of your machine. All you need is a browser.

Colab is used extensively in the machine learning community with applications including:

Getting started with TensorFlow


Developing and training neural networks
Experimenting with TPUs
Disseminating AI research
Creating tutorials

To see sample Colab notebooks that demonstrate machine learning applications, see the machine learning examples below.

More Resources
Working with Notebooks in Colab
Overview of Colaboratory
Guide to Markdown
Importing libraries and installing dependencies
Saving and loading notebooks in GitHub
Interactive forms
Interactive widgets
TensorFlow 2 in Colab

Working with Data


Loading data: Drive, Sheets, and Google Cloud Storage
Charts: visualizing data
Getting started with BigQuery
Machine Learning Crash Course
These are a few of the notebooks from Google's online Machine Learning course. See the full course website for more.

Intro to Pandas
Tensor ow concepts
First steps with TensorFlow
Intro to neural nets
Intro to sparse data and embeddings

Using Accelerated Hardware


TensorFlow with GPUs
TensorFlow with TPUs

Machine Learning Examples


To see end-to-end examples of the interactive machine learning analyses that Colaboratory makes possible, check out the Seed
project.

A few featured examples:

Neural Style Transfer: Use deep learning to transfer style between images.
EZ NSynth: Synthesize audio with WaveNet auto-encoders.
Fashion MNIST with Keras and TPUs: Classify fashion-related images with deep learning.
DeepDream: Produce DeepDream images from your own photos.
Convolutional VAE: Create a generative model of handwritten digits.

import numpy as np
from numpy import inf

d = np.array([
[0,5,15,4]
, [5,0,4,8]
, [15,4,0,1]
, [4,8,1,0]
])

iteration = 20
n_ants = 4
n_citys = 4

m= n_ants
n= n_citys

e= .5
alpha=1
beta=2

visibility = 1/d
visibility[visibility == inf] = 0

pheromne = .1*np.ones((m,n))

rute=np.ones((m,n+1))

for ite in range(iteration):


rute[:,0]=1
print("Fetching ITERATION" , ite+1)

for i in range(m):
temp_visibility = np.array(visibility)

for j in range(n-1):
combine_feature=np.zeros(5)
cum_prob = np.zeros(5)

cur_loc= int(rute[i,j]-1)

temp_visibility[:,cur_loc] = 0

p_feature = np.power(pheromne[cur_loc,:],beta)
v_feature = np.power(temp_visibility[cur_loc,:],alpha)

p_feature = p_feature[:,np.newaxis]
v_feature = v_feature[:,np.newaxis]

combine_feature = np.multiply(p_feature,v_feature)

total = np.sum(combine_feature)

probs = combine_feature/total

cum_prob = np.cumsum(probs)

r=np.random.random_sample()

city= np.nonzero(cum_prob>r)[0][0]+1

rute[i,j+1] = city

left = list(set([i for i in range(1,n+1)])-set(rute[i,:-2]))[0]


rute[1,-2]=left

rute_opt = np.array(rute)
dist_cost = np.zeros((m,1))

for i in range(m):
s=0
for j in range(n-1):
s=s+d[int(rute_opt[i,j])-1, int(rute_opt[i,j+1])-1]

dist_cost[i]=s

dist_min_loc=np.argmin(dist_cost)
dist_min_cost=dist_cost[dist_min_loc]

best_route=rute[dist_min_loc,:]
pheromne=(1-e)*pheromne

for i in range (m):


for j in range(n-1):
dt=1/dist_cost[i]
pheromne[
int(rute_opt[i,j])-1,
int(rute_opt[i,j+1])-1
] = pheromne [
int(rute_opt[i,j])-1,
int(rute_opt[i,j+1])-1
] + dt
Fetching ITERATION 1
Fetching ITERATION 2
Fetching ITERATION 3
Fetching ITERATION 4
Fetching ITERATION 5
Fetching ITERATION 6
Fetching ITERATION 7
Fetching ITERATION 8
Fetching ITERATION 9
Fetching ITERATION 10
Fetching ITERATION 11
Fetching ITERATION 12
Fetching ITERATION 13
Fetching ITERATION 14
Fetching ITERATION 15
Fetching ITERATION 16
Fetching ITERATION 17
Fetching ITERATION 18
Fetching ITERATION 19
Fetching ITERATION 20
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:22: RuntimeWarning: divide by zero encountered in t

print('route of all the ants at the end : ')


print(rute_opt)
print()

print('best path :' ,best_route)


print('cost of the best path', int(dist_min_cost[0]) + d[int(best_route[-2])-1,0])

route of all the ants at the end :


[[1. 4. 3. 2. 1.]
[1. 4. 3. 2. 1.]
[1. 4. 3. 2. 1.]
[1. 4. 3. 2. 1.]]

best path : [1. 4. 3. 2. 1.]


cost of the best path 14

You might also like