markdown
stringlengths
0
37k
code
stringlengths
1
33.3k
path
stringlengths
8
215
repo_name
stringlengths
6
77
license
stringclasses
15 values
However, in order to implement this, we need a list of bonds. We will do this by taking a system minimized under our original harmonic_morse potential:
R_temp, max_force_component = run_minimization(harmonic_morse_pair(displacement,D0=5.0,alpha=10.0,r0=1.0,k=500.0), R, shift) print('largest component of force after minimization = {}'.format(max_force_component)) plot_system( R_temp, box_size )
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
We now place a bond between all particle pairs that are separated by less than 1.3. calculate_bond_data returns a list of such bonds, as well as a list of the corresponding current length of each bond.
bonds, lengths = calculate_bond_data(displacement, R_temp, 1.3) print(bonds[:5]) # list of particle index pairs that form bonds print(lengths[:5]) # list of the current length of each bond
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
We use this length as the r0 parameter, meaning that initially each bond is at the unstable local maximum $r=r_0$.
bond_energy_fn = bistable_spring_bond(displacement, bonds, r0=lengths)
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
We now use our new bond_energy_fn to minimize the energy of the system. The expectation is that nearby particles should either move closer together or further apart, and the choice of which to do should be made collectively due to the constraint of constant volume. This is exactly what we see.
Rfinal, max_force_component = run_minimization(bond_energy_fn, R_temp, shift) print('largest component of force after minimization = {}'.format(max_force_component)) plot_system( Rfinal, box_size )
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Specifying bonds dynamically As with species or parameters, bonds can be specified dynamically, i.e. when the energy function is called. Importantly, note that this does NOT override bonds that were specified statically in smap.bond.
# Specifying the bonds dynamically ADDS additional bonds. # Here, we dynamically pass the same bonds that were passed statically, which # has the effect of doubling the energy print(bond_energy_fn(R)) print(bond_energy_fn(R,bonds=bonds, r0=lengths))
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
We won't go thorugh a further example as the implementation is exactly the same as specifying species or parameters dynamically, but the ability to employ bonds both statically and dynamically is a very powerful and general framework. Combining potentials Most JAX MD functionality (e.g. simulations, energy minimization...
# Note, the code in the "Bonds" section must be run prior to this. energy_fn = harmonic_morse_pair(displacement,D0=0.,alpha=10.0,r0=1.0,k=1.0) bond_energy_fn = bistable_spring_bond(displacement, bonds, r0=lengths) def combined_energy_fn(R): return energy_fn(R) + bond_energy_fn(R)
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Here, we have set $D_0=0$, so the pair potential is just a one-sided repulsive harmonic potential. For particles connected with a bond, this raises the energy of the "contracted" minimum relative to the "extended" minimum.
drs = np.arange(0,2,0.01) U = harmonic_morse(drs,D0=0.,alpha=10.0,r0=1.0,k=1.0)+bistable_spring(drs) plt.plot(drs,U) format_plot(r'$r$', r'$V(r)$') finalize_plot()
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
This new energy function can be passed to the minimization routine (or any other JAX MD simulation routine) in the usual way.
Rfinal, max_force_component = run_minimization(combined_energy_fn, R_temp, shift) print('largest component of force after minimization = {}'.format(max_force_component)) plot_system( Rfinal, box_size )
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Specifying forces instead of energies So far, we have defined functions that calculate the energy of the system, which we then pass to JAX MD. Internally, JAX MD uses automatic differentiation to convert these into functions that calculate forces, which are necessary to evolve a system under a given dynamics. However, ...
N_0 = N // 2 # Half the particles in species 0 N_1 = N - N_0 # The rest in species 1 species = np.array([0]*N_0 + [1]*N_1, dtype=np.int32) print(species)
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Next, we we creat our custom force function. Starting with our harmonic_morse pair potential, we calculate the force manually (i.e. using built-in automatic differentiation), and then multiply the force by the species id, which has the desired effect.
energy_fn = harmonic_morse_pair(displacement,D0=5.0,alpha=10.0,r0=1.0,k=500.0) force_fn = quantity.force(energy_fn) def custom_force_fn(R, **kwargs): return vmap(lambda a,b: a*b)(force_fn(R),species)
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Running simulations with custom forces is as easy as passing this force function to the simulation.
def run_minimization_general(energy_or_force, R_init, shift, num_steps=5000): dt_start = 0.001 dt_max = 0.004 init,apply=minimize.fire_descent(jit(energy_or_force),shift,dt_start=dt_start,dt_max=dt_max) apply = jit(apply) @jit def scan_fn(state, i): return apply(state), 0. state = init(R_init) s...
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
We run this as usual,
key, split = random.split(key) Rfinal, _ = run_minimization_general(custom_force_fn, R, shift) plot_system( Rfinal, box_size, species )
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
After the above minimization, the blue particles have the same positions as they did initially:
plot_system( R, box_size, species )
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Note, this method for fixing particles only works when there is no stochastic noise (e.g. in Langevin or Brownian dynamics) because such noise affects partices whether or not they have a net force. A safer way to fix particles is to create a custom shift function. Coupled ensembles For a final example that demonstrates...
energy_fn = harmonic_morse_pair(displacement,D0=5.0,alpha=10.0,r0=0.5,k=500.0) def spring_energy_fn(Rall, k_spr=50.0, **kwargs): metric = vmap(space.canonicalize_displacement_or_metric(displacement), (0, 0), 0) dr = metric(Rall[0],Rall[1]) return 0.5*k_spr*np.sum((dr)**2) def total_energy_fn(Rall, **kwargs): re...
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
We now have to define a new shift function that can handle arrays of shape $(2,N,d)$. In addition, we make two copies of our initial positions R, one for each system.
def shift_all(Rall, dRall, **kwargs): return vmap(shift)(Rall, dRall) Rall = np.array([R,R])
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Now, all we have to do is pass our custom energy and shift functions, as well as the $(2,N,d)$ dimensional initial position, to JAX MD, and proceed as normal. As a demonstration, we define a simple and general Brownian Dynamics simulation function, similar to the simulation routines above except without the special ca...
def run_brownian_simple(energy_or_force, R_init, shift, key, num_steps): init, apply = simulate.brownian(energy_or_force, shift, dt=0.00001, kT=1.0, gamma=0.1) apply = jit(apply) @jit def scan_fn(state, t): return apply(state), 0 key, split = random.split(key) state = init(split, R_init) state, _ =...
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
Note that nowhere in this function is there any indication that we are simulating an ensemble of systems. This comes entirely form the inputs: i.e. the energy function, the shift function, and the set of initial positions.
key, split = random.split(key) Rall_final = run_brownian_simple(total_energy_fn, Rall, shift_all, split, num_steps=10000)
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
The output also has shape $(2,N,d)$. If we display the results, we see that the two systems are in similar, but not identical, positions, showing that we have succeeded in simulating a coupled ensemble.
for Ri in Rall_final: plot_system( Ri, box_size ) finalize_plot((0.5,0.5))
notebooks/customizing_potentials_cookbook.ipynb
google/jax-md
apache-2.0
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืชื•ื›ืœื• ืœื™ืฆื•ืจ ื‘ืขืฆืžื›ื ืคื•ื ืงืฆื™ื” ืฉื™ื•ืฆืจืช ืžืฉืชืžืฉ ื—ื“ืฉ?<br> ื–ื” ืœื ืžืกื•ื‘ืš ืžื“ื™: </p>
def create_user(first_name, last_name, nickname, current_age): return { 'first_name': first_name, 'last_name': last_name, 'nickname': nickname, 'age': current_age, } # ื ืงืจื ืœืคื•ื ืงืฆื™ื” ื›ื“ื™ ืœืจืื•ืช ืฉื”ื›ืœ ืขื•ื‘ื“ ื›ืžืฆื•ืคื” new_user = create_user('Bayta', 'Darell', 'Bay', 24) print(new_user)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> <mark>ื ื•ื›ืœ ื’ื ืœืžืžืฉ ืคื•ื ืงืฆื™ื•ืช ืฉื™ืขื–ืจื• ืœื ื• ืœื‘ืฆืข ืคืขื•ืœื•ืช ืขืœ ื›ืœ ืื—ื“ ืžื”ืžืฉืชืžืฉื™ื.</mark><br> ืœื“ื•ื’ืžื”: ื”ืคื•ื ืงืฆื™ื” <var>describe_as_a_string</var> ืชืงื‘ืœ ืžืฉืชืžืฉ ื•ืชื—ื–ื™ืจ ืœื ื• ืžื—ืจื•ื–ืช ืฉืžืชืืจืช ืื•ืชื•,<br> ื•ื”ืคื•ื ืงืฆื™ื” <var>celeberate_birthday</var> ืชืงื‘ืœ ืžืฉืชืžืฉ ื•ืชื’ื“...
def describe_as_a_string(user): first_name = user['first_name'] last_name = user['last_name'] full_name = f'{first_name} {last_name}' nickname = user['nickname'] age = user['age'] return f'{nickname} ({full_name}) is {age} years old.' def celebrate_birthday(user): user['age'] = user['age']...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<div class="align-center" style="display: flex; text-align: right; direction: rtl;"> <div style="display: flex; width: 10%; float: right; "> <img src="images/recall.svg" style="height: 50px !important;" alt="ืชื–ื›ื•ืจืช" title="ืชื–ื›ื•ืจืช"> </div> <div style="width: 90%"> <p style="text-align: right...
class User: pass
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<div class="align-center" style="display: flex; text-align: right; direction: rtl;"> <div style="display: flex; width: 10%; float: right; "> <img src="images/recall.svg" style="height: 50px !important;" alt="ืชื–ื›ื•ืจืช" title="ืชื–ื›ื•ืจืช"> </div> <div style="width: 90%"> <p style="text-align: right...
user1 = User()
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื›ืขืช ื™ืฆืจื ื• ืžืฉืชืžืฉ, ื•ืื ื—ื ื• ื™ื›ื•ืœื™ื ืœืฉื ื•ืช ืืช ื”ืชื›ื•ื ื•ืช ืฉืœื•.<br> ืžื‘ื—ื™ื ื” ืžื™ืœื•ืœื™ืช, ื ื”ื•ื’ ืœื”ื’ื™ื“ ืฉื™ืฆืจื ื• <dfn>ืžื•ืคืข</dfn> (<dfn>Instance</dfn>) ืื• <dfn>ืขืฆื</dfn> (ืื•ื‘ื™ื™ืงื˜, <dfn>Object</dfn>) ืžืกื•ื’ <var>User</var>, ืฉืฉืžื• <var>user1</var>.<br> ื”ืฉืชืžืฉื ื• ืœ...
user1.first_name = "Miles" user1.last_name = "Prower" user1.age = 8 user1.nickname = "Tails"
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื ื•ื›ืœ ืœืื—ื–ืจ ืืช ื”ืชื›ื•ื ื•ืช ื”ืœืœื• ื‘ืงืœื•ืช, ื‘ืื•ืชื” ื”ืฆื•ืจื”: </p>
print(user1.age)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื•ืื ื ื‘ื“ื•ืง ืžื” ื”ืกื•ื’ ืฉืœ ื”ืžืฉืชื ื” <var>user1</var>, ืžืฆืคื” ืœื ื• ื”ืคืชืขื” ื ื—ืžื“ื”: </p>
type(user1)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืื™ื–ื” ื™ื•ืคื™! ื”ืžื—ืœืงื” ื’ืจืžื” ืœื›ืš ืฉึพ<var>User</var> ื”ื•ื ืžืžืฉ ืกื•ื’ ืžืฉืชื ื” ื‘ืคื™ื™ืชื•ืŸ ืขื›ืฉื™ื•.<br> ืงื—ื• ืœืขืฆืžื›ื ืจื’ืข ืœื”ืชืคืขืœ โ€“ ื™ืฆืจื ื• ืกื•ื’ ืžืฉืชื ื” ื—ื“ืฉ ื‘ืคื™ื™ืชื•ืŸ!<br> ืื ื›ืš, ื”ืžืฉืชื ื” <var>user1</var> ืžืฆื‘ื™ืข ืขืœ ืžื•ืคืข ืฉืœ ืžืฉืชืžืฉ, ืฉืกื•ื’ื• <var>User</var>. </p> <p style="t...
user2 = User() user2.first_name = "Harry" user2.last_name = "Potter" user2.age = 39 user2.nickname = "BoyWhoLived1980"
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื•ื ืฉื™ื ืœื‘ ืฉืฉื ื™ ื”ืžื•ืคืขื™ื ืžืชืงื™ื™ืžื™ื ื–ื” ืœืฆื“ ื–ื”, ื•ืœื ื“ื•ืจืกื™ื ืืช ื”ืขืจื›ื™ื ื–ื” ืฉืœ ื–ื”: </p>
print(f"{user1.first_name} {user1.last_name} is {user1.age} years old.") print(f"{user2.first_name} {user2.last_name} is {user2.age} years old.")
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื”ืžืฆื‘ ื”ื–ื” ืžืชืงื™ื™ื ื›ื™ื•ื•ืŸ ืฉื›ืœ ืงืจื™ืื” ืœืžื—ืœืงื” <var>User</var> ื™ื•ืฆืจืช ืžื•ืคืข ื—ื“ืฉ ืฉืœ ืžืฉืชืžืฉ.<br> ื›ืœ ืื—ื“ ืžื”ืžื•ืคืขื™ื ื”ื•ื ื™ืฉื•ืช ื ืคืจื“ืช ืฉืžืชืงื™ื™ืžืช ื‘ื–ื›ื•ืช ืขืฆืžื”. </p> <div class="align-center" style="display: flex; text-align: right; direction: rtl; clear: both;"...
def describe_as_a_string(user): full_name = f'{user.first_name} {user.last_name}' return f'{user.nickname} ({full_name}) is {user.age} years old.' print(describe_as_a_string(user2))
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื”ืคื•ื ืงืฆื™ื” ืขื“ื™ื™ืŸ ืžืกืชื•ื‘ื‘ืช ืœื” ื—ื•ืคืฉื™ื™ื” ื•ืœื ืžืื•ื’ื“ืช ืชื—ืช ืืฃ ืžื‘ื ื” โ€“ ื•ื–ื” ื‘ื“ื™ื•ืง ื”ืžืฆื‘ ืฉื ื™ืกื™ื ื• ืœืžื ื•ืข.<br> ืœืžื–ืœื ื• ื”ืคืชืจื•ืŸ ืœื‘ืขื™ื™ืช ืื™ื’ื•ื“ ื”ืงื•ื“ ื”ื•ื ืคืฉื•ื˜. ื ื•ื›ืœ ืœื”ื“ื‘ื™ืง ืืช ืงื•ื“ ื”ืคื•ื ืงืฆื™ื” ืชื—ืช ื”ืžื—ืœืงื” <code>User</code>: </p>
class User: def describe_as_a_string(user): full_name = f'{user.first_name} {user.last_name}' return f'{user.nickname} ({full_name}) is {user.age} years old.' user3 = User() user3.first_name = "Anthony John" user3.last_name = "Soprano" user3.age = 61 user3.nickname = "Tony"
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื‘ืชื ืฉืœืžืขืœื” ื”ื’ื“ืจื ื• ืืช ื”ืคื•ื ืงืฆื™ื” <var>describe_as_a_string</var> ื‘ืชื•ืš ื”ืžื—ืœืงื” <var>User</var>.<br> ืคื•ื ืงืฆื™ื” ืฉืžื•ื’ื“ืจืช ื‘ืชื•ืš ืžื—ืœืงื” ื ืงืจืืช <dfn>ืคืขื•ืœื”</dfn> (<dfn>Method</dfn>), ืฉื ืฉื ื™ืชืŸ ืœื” ื›ื“ื™ ืœื‘ื“ืœ ืื•ืชื” ืžื™ืœื•ืœื™ืช ืžืคื•ื ืงืฆื™ื” ืจื’ื™ืœื”. </p> <p style="text-a...
user3.describe_as_a_string()
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื—ื“ื™ ื”ืขื™ืŸ ืฉืžื• ื•ื“ืื™ ืœื‘ ืœืžืฉื”ื• ืžืขื˜ ืžืฉื•ื ื” ื‘ืงืจื™ืื” ืœืคืขื•ืœื” <var>describe_as_a_string</var>.<br> ื”ืคืขื•ืœื” ืžืฆืคื” ืœืงื‘ืœ ืคืจืžื˜ืจ (ืงืจืื ื• ืœื• <var>user</var>), ืื‘ืœ ื›ืฉืงืจืื ื• ืœื” ื‘ืชื ื”ืื—ืจื•ืŸ ืœื ื”ืขื‘ืจื ื• ืœื” ืืฃ ืืจื’ื•ืžื ื˜!<br> </p> <p style="text-align: right; direction...
class User: def describe_as_a_string(self): full_name = f'{self.first_name} {self.last_name}' return f'{self.nickname} ({full_name}) is {self.age} years old.' user3 = User() user3.first_name = "Anthony John" user3.last_name = "Soprano" user3.age = 61 user3.nickname = "Tony" user3.describe_as_a_str...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<div class="align-center" style="display: flex; text-align: right; direction: rtl;"> <div style="display: flex; width: 10%; float: right; "> <img src="images/warning.png" style="height: 50px !important;" alt="ืื–ื”ืจื”!"> </div> <div style="width: 90%"> <p style="text-align: right; direction: r...
def create_user(first_name, last_name, nickname, current_age): user = User() user.first_name = first_name user.last_name = last_name user.nickname = nickname user.age = current_age return user user4 = create_user('Daenerys', 'Targaryen', 'Mhysa', 23) print(f"{user4.first_name} {user4.last_name...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืื‘ืœ ื”ื’ื“ืจื” ืฉื›ื–ื•, ื›ืžื• ืฉื›ื‘ืจ ืืžืจื ื•, ืกื•ืชืจืช ืืช ื›ืœ ื”ืจืขื™ื•ืŸ ืฉืœ ืžื—ืœืงื•ืช.<br> ื”ืจื™ ื”ืžื˜ืจื” ืฉืœ ืžื—ืœืงื•ืช ื”ื™ื ืงื™ื‘ื•ืฅ ื›ืœ ืžื” ืฉืงืฉื•ืจ ื‘ื ื™ื”ื•ืœ ื”ืชื›ื•ื ื•ืช ื•ื”ืคืขื•ืœื•ืช ืชื—ืช ื”ืžื—ืœืงื”. </p> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ื ืขืชื™ืง ืืช ...
class User: def describe_as_a_string(self): full_name = f'{self.first_name} {self.last_name}' return f'{self.nickname} ({full_name}) is {self.age} years old.' def create_user(self, first_name, last_name, nickname, current_age): self.first_name = first_name self.last_name = last_...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืขื›ืฉื™ื• ื ื•ื›ืœ ืœื™ืฆื•ืจ ืžืฉืชืžืฉ ื—ื“ืฉ, ื‘ืฆื•ืจื” ื”ื—ื‘ื™ื‘ื” ื•ื”ืžืงื•ืฆืจืช ื”ื‘ืื”: </p>
user4 = User() user4.create_user('Daenerys', 'Targaryen', 'Mhysa', 23) user4.describe_as_a_string()
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<span style="text-align: right; direction: rtl; float: right; clear: both;">ืชืจื’ื™ืœ ื‘ื™ื ื™ื™ื: ืžื—ืœืงืช ื ืงื•ื“ื•ืช</span> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ืžื™ื ืจื•ื•ื” ืžืงื’ื•ื ื’ืœ ื™ืฆืื” ืœื‘ื™ืœื•ื™ ืœื™ืœื™ ื‘ืกืžื˜ืช ื“ื™ืื’ื•ืŸ,<br> ื•ืื—ืจื™ ืœื™ืœื” ืขืžื•ืก ื‘ืฉืชื™ื™ืช ืฉื™ื›ืจ ื‘ืงืœื—ืช ื”ืจื•ืชื—ืช, ื”ื™ื ืžืขื˜ ืžืชืงืฉื” ืœื—ื–ื•ืจ ืœื”ื•ื’ื•ื•ืจื˜ืก. </p>...
current_location = Point() current_location.create_point(5, 3) if current_location.distance() == 8: print("Success!")
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<span style="text-align: right; direction: rtl; float: right; clear: both;">ืคืขื•ืœื•ืช ืงืกื</span> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ื›ื“ื™ ืœื”ืงืœ ืืคื™ืœื• ืขื•ื“ ื™ื•ืชืจ ืขืœ ื”ืžืœืื›ื”, ื‘ืคื™ื™ืชื•ืŸ ื™ืฉ <dfn>ืคืขื•ืœื•ืช ืงืกื</dfn> (<dfn>Magic Methods</dfn>).<br> ืืœื• ืคืขื•ืœื•ืช ืขื ืฉื ืžื™ื•ื—ื“, ืฉืื ื ื’ื“ื™ืจ ืื•ืชืŸ ื‘ืžื—ืœืง...
user4 = User() user4.create_user('Daenerys', 'Targaryen', 'Mhysa', 23) str(user4)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืคื™ื™ืชื•ืŸ ืืžื ื ืื•ืžืจืช ื“ื‘ืจื™ื ื ื›ื•ื ื™ื, ื›ืžื• ืฉืžื“ื•ื‘ืจ ื‘ืื•ื‘ื™ื™ืงื˜ (ืžื•ืคืข) ืžื”ืžื—ืœืงื” <var>User</var> ื•ืืช ื”ื›ืชื•ื‘ืช ืฉืœื• ื‘ื–ื™ื›ืจื•ืŸ, ืื‘ืœ ื–ื” ืœื ื‘ืืžืช ืžื•ืขื™ืœ.<br> </p> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ื›ื™ื•ื•ืŸ ืฉืคื•ื ืงืฆื™ื™ืช ื”ื”ื“ืคืกื” <v...
print(user4)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื”ืžื—ืœืงื” ืฉืœื ื•, ื›ืžื•ื‘ืŸ, ื›ื‘ืจ ืขืจื•ื›ื” ืœื”ืชืžื•ื“ื“ ืขื ื”ืžืฆื‘.<br> ื‘ื–ื›ื•ืช ื”ืคืขื•ืœื” <var>describe_as_a_string</var> ืฉื”ื’ื“ืจื ื• ืงื•ื“ื ืœื›ืŸ ื ื•ื›ืœ ืœื”ื“ืคื™ืก ืืช ืคืจื˜ื™ ื”ืžืฉืชืžืฉ ื‘ืงืœื•ืช ื™ื—ืกื™ืช: </p>
print(user4.describe_as_a_string())
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืื‘ืœ ื™ืฉ ื“ืจืš ืงืœื” ืขื•ื“ ื™ื•ืชืจ!<br> ื ื™ื—ืฉืชื ื ื›ื•ืŸ โ€“ ืคืขื•ืœืช ื”ืงืกื <code>__str__</code>.<br> ื ื—ืœื™ืฃ ืืช ื”ืฉื ืฉืœ ื”ืคืขื•ืœื” <var>describe_as_a_string</var>, ืœึพ<code>__str__</code>: </p>
class User: def __str__(self): full_name = f'{self.first_name} {self.last_name}' return f'{self.nickname} ({full_name}) is {self.age} years old.' def create_user(self, first_name, last_name, nickname, current_age): self.first_name = first_name self.last_name = last_name ...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืจืื• ืื™ื–ื” ืงืกื! ืขื›ืฉื™ื• ื”ืžืจื” ืฉืœ ื›ืœ ืžื•ืคืข ืžืกื•ื’ <var>User</var> ืœืžื—ืจื•ื–ืช ื”ื™ื ืคืขื•ืœื” ืžืžืฉ ืคืฉื•ื˜ื”!<br> </p> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ื‘ืชื ืฉืœืžืขืœื”, ื”ื’ื“ืจื ื• ืืช ืคืขื•ืœืช ื”ืงืกื <code>__str__</code>.<br> ื”ืคืขื•ืœ...
class User: def __init__(self): print("New user has been created!") def __str__(self): full_name = f'{self.first_name} {self.last_name}' return f'{self.nickname} ({full_name}) is {self.age} years old.' def create_user(self, first_name, last_name, nickname, current_age): sel...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื‘ื“ื•ื’ืžืช ื”ืงื•ื“ ืฉืœืžืขืœื” ื”ื’ื“ืจื ื• ืืช ืคืขื•ืœืช ื”ืงืกื <code>__init__</code>, ืฉืชืจื•ืฅ ืžื™ื™ื“ ื›ืฉื ื•ืฆืจ ืžื•ืคืข ื—ื“ืฉ.<br> ื”ื—ืœื˜ื ื• ืฉื‘ืจื’ืข ืฉื™ื™ื•ื•ืฆืจ ืžื•ืคืข ืฉืœ ืžืฉืชืžืฉ, ืชื•ื“ืคืก ื”ื”ื•ื“ืขื” <samp dir="ltr">New user has been created!</samp>. </p> <p style="text-align: right; directio...
class User: def __init__(self, message): self.creation_message = message print(self.creation_message) def __str__(self): full_name = f'{self.first_name} {self.last_name}' return f'{self.nickname} ({full_name}) is {self.age} years old.' def create_user(self, first_name, last...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื‘ืชื ืฉืœืžืขืœื” ื”ื’ื“ืจื ื• ืฉืคืขื•ืœืช ื”ืงืกื <code>__init__</code> ืชืงื‘ืœ ื›ืคืจืžื˜ืจ ื”ื•ื“ืขื” ืœื”ื“ืคืกื”.<br> ื”ื”ื•ื“ืขื” ืชื™ืฉืžืจ ื‘ืชื›ื•ื ื” <var>creation_message</var> ื”ืฉื™ื™ื›ืช ืœืžื•ืคืข, ื•ืชื•ื“ืคืก ืžื™ื™ื“ ืœืื—ืจ ืžื›ืŸ.<br> ืืช ื”ื”ื•ื“ืขื” ื”ืขื‘ืจื ื• ื›ืืจื’ื•ืžื ื˜ ื‘ืขืช ื”ืงืจื™ืื” ืœืฉื ื”ืžื—ืœืงื”, <var>User</var>...
class User: def __init__(self, first_name, last_name, nickname, current_age): self.first_name = first_name self.last_name = last_name self.nickname = nickname self.age = current_age print("Yayy! We have just created a new instance! :D") def __str__(self): full_na...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ืื™ื’ื“ื ื• ืืช ื™ืฆื™ืจืช ืชื›ื•ื ื•ืช ื”ืžื•ืคืข ืชื—ืช ืคืขื•ืœื” ืื—ืช, ืฉืจืฆื” ื›ืฉื”ื•ื ื ื•ืฆืจ.<br> ื”ืจืขื™ื•ืŸ ื”ื ืคืœื ื”ื–ื” ื ืคื•ืฅ ืžืื•ื“ ื‘ืฉืคื•ืช ืชื›ื ื•ืช ืฉืชื•ืžื›ื•ืช ื‘ืžื—ืœืงื•ืช, ื•ืžื•ื›ืจืช ื‘ืฉื <dfn>ืคืขื•ืœืช ืืชื—ื•ืœ</dfn> (<dfn>Initialization Method</dfn>).<br> ื–ื• ื’ื ื”ืกื™ื‘ื” ืœืฉื ื”ืคืขื•ืœื” โ€“ ื”ืžื™ืœื” init ื ื’ื–...
snailchat_users = [ ['Mike', 'Shugarberg', 'Marker', 36], ['Hammer', 'Doorsoy', 'Tzweetz', 43], ['Evan', 'Spygirl', 'Odd', 30], ]
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื ื ื™ื—, ืœื›ืื•ืจื” ื‘ืœื‘ื“, ืฉืื ื—ื ื• ืจื•ืฆื™ื ืœื”ืขืชื™ืง ืืช ืื•ืชื” ืจืฉื™ืžืช ืžืฉืชืžืฉื™ื ื•ืœืฆืจืฃ ืื•ืชื” ืœืจืฉืช ื”ื—ื‘ืจืชื™ืช ืฉืœื ื•.<br> ืงื—ื• ื“ืงื” ื•ื—ืฉื‘ื• ืื™ืš ื”ื™ื™ืชื ืขื•ืฉื™ื ืืช ื–ื”. </p> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ื–ื›ืจื• ืฉืงืจื™ืื” ืœืžื—ืœืงื” <va...
our_users = [] for user_details in snailchat_users: new_user = User(*user_details) # Unpacking โ€“ ื”ืชื ื”ืจืืฉื•ืŸ ืขื•ื‘ืจ ืœืคืจืžื˜ืจ ื”ืชื•ืื, ื•ื›ืš ื’ื ื”ืฉื ื™, ื”ืฉืœื™ืฉื™ ื•ื”ืจื‘ื™ืขื™ our_users.append(new_user) print(new_user)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื‘ืงื•ื“ ืฉืœืžืขืœื” ื™ืฆืจื ื• ืจืฉื™ืžื” ืจื™ืงื”, ืฉืื•ืชื” ื ืžืœื ื‘ืžืฉืชืžืฉื™ื <strike>ืฉื ื’ื ื•ื‘</strike> ืฉื ืฉืื™ืœ ืžืกื ื™ื™ืœืฆ'ืื˜.<br> ื ืขื‘ื™ืจ ืืช ื”ืคืจื˜ื™ื ืฉืœ ื›ืœ ืื—ื“ ืžื”ืžืฉืชืžืฉื™ื ื”ืžื•ืคื™ืขื™ื ื‘ึพ<var>snailchat_users</var>, ืœึพ<code>__init__</code> ืฉืœ <var>User</var>,<br> ื•ื ืฆืจืฃ ืืช ื”ืžื•ืคืข...
print(our_users[0]) print(our_users[1]) print(our_users[2])
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<div class="align-center" style="display: flex; text-align: right; direction: rtl; clear: both;"> <div style="display: flex; width: 10%; float: right; clear: both;"> <img src="images/exercise.svg" style="height: 50px !important;" alt="ืชืจื’ื•ืœ"> </div> <div style="width: 70%"> <p style="text-a...
class User: def __init__(self, first_name, last_name, nickname, current_age): self.first_name = first_name self.last_name = last_name self.nickname = nickname self.age = current_age def celebrate_birthday(self): age = age + 1 def __str__(self): full_name...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื ื™ืกื™ื•ืŸ ืœื™ืฆื•ืจ ืžื•ืคืข ืฉืœ ืžืฉืชืžืฉ ื•ืœื—ื’ื•ื’ ืœื• ื™ื•ื ื”ื•ืœื“ืช ื™ื’ืจื•ื ืœืฉื’ื™ืื”.<br> ืชื•ื›ืœื• ืœื ื—ืฉ ืžื” ืชื”ื™ื” ื”ืฉื’ื™ืื” ืขื•ื“ ืœืคื ื™ ืฉืชืจื™ืฆื•? </p>
user6 = User('Winston', 'Smith', 'Jeeves', 39) user6.celebrate_birthday()
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื ื™ืกื™ื ื• ืœืฉื ื•ืช ืืช ื”ืžืฉืชื ื” <var>age</var> โ€“ ืืš ื”ื•ื ืื™ื ื• ืžื•ื’ื“ืจ.<br> ื›ื“ื™ ืœืฉื ื•ืช ืืช ื”ื’ื™ืœ ืฉืœ ื”ืžืฉืชืžืฉ ืฉื™ืฆืจื ื•, ื ื”ื™ื” ื—ื™ื™ื‘ื™ื ืœื”ืชื™ื™ื—ืก ืœึพ<code>self.age</code>.<br> ืื ืœื ื ืฆื™ื™ืŸ ื‘ืžืคื•ืจืฉ ืฉืื ื—ื ื• ืจื•ืฆื™ื ืœืฉื ื•ืช ืืช ื”ืชื›ื•ื ื” <var>age</var> ืฉืฉื™ื™ื›ืช ืœึพ<var>self</var...
class User: def __init__(self, first_name, last_name, nickname, current_age): self.first_name = first_name self.last_name = last_name self.nickname = nickname self.age = current_age def celebrate_birthday(self): self.age = self.age + 1 def __str__(self): ...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื‘ืื•ืชื” ื”ืžื™ื“ื”, ืชื›ื•ื ื•ืช ืฉื”ื•ื’ื“ืจื• ื›ื—ืœืง ืžืžื•ืคืข ืœื ืžื•ื’ื“ืจื•ืช ืžื—ื•ืฆื” ืœื•.<br> ืืคืฉืจ ืœื”ืฉืชืžืฉ, ืœื“ื•ื’ืžื”, ื‘ืฉื ื”ืžืฉืชื ื” <var>age</var> ืžื‘ืœื™ ืœื—ืฉื•ืฉ ืœืคื’ื•ืข ื‘ืชืคืงื•ื“ ื”ืžื—ืœืงื” ืื• ื‘ืชืคืงื•ื“ ื”ืžื•ืคืขื™ื: </p>
user6 = User('Winston', 'Smith', 'Jeeves', 39) print(user6) age = 10 print(user6)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื›ื“ื™ ืœืฉื ื•ืช ืืช ื’ื™ืœื• ืฉืœ ื”ืžืฉืชืžืฉ, ื ืฆื˜ืจืš ืœื”ืชื™ื™ื—ืก ืืœ ื”ืชื›ื•ื ื” ืฉืœื• ื‘ืฆื•ืจืช ื”ื›ืชื™ื‘ื” ืฉืœืžื“ื ื•: </p>
user6.age = 10 print(user6)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<span style="text-align: right; direction: rtl; float: right; clear: both;">ืชื›ื•ื ื” ืื• ืคืขื•ืœื” ืฉืœื ืงื™ื™ืžื•ืช</span> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ืฉื’ื™ืื” ืฉืžืชืจื—ืฉืช ืœื ืžืขื˜ ื”ื™ื ืคื ื™ื™ื” ืœืชื›ื•ื ื” ืื• ืœืคืขื•ืœื” ืฉืœื ืงื™ื™ืžื•ืช ืขื‘ื•ืจ ื”ืžื•ืคืข.<br> ืœื“ื•ื’ืžื”: </p>
class Dice: def __init__(self, number): if 1 <= number <= 6: self.is_valid = True dice_bag = [Dice(roll_result) for roll_result in range(7)]
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื™ืฆืจื ื• ืจืฉื™ืžืช ืงื•ื‘ื™ื•ืช ื•ื‘ื™ืฆืขื ื• ื”ืฉืžื” ื›ืš ืฉึพ<var>dice_bag</var> ืชืฆื‘ื™ืข ืขืœื™ื”.<br> ื›ืขืช ื ื“ืคื™ืก ืืช ื”ืชื›ื•ื ื” <var>is_valid</var> ืฉืœ ื›ืœ ืื—ืช ืžื”ืงื•ื‘ื™ื•ืช: </p>
for dice in dice_bag: print(dice.is_valid)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<p style="text-align: right; direction: rtl; float: right; clear: both;"> ื”ื‘ืขื™ื” ื”ื™ื ืฉื”ืงื•ื‘ื™ื” ื”ืจืืฉื•ื ื” ืฉื™ืฆืจื ื• ืงื™ื‘ืœื” ืืช ื”ืžืกืคืจ 0.<br> ื‘ืžืงืจื” ื›ื–ื”, ื”ืชื ืื™ ื‘ืคืขื•ืœืช ื”ืืชื—ื•ืœ (<code>__init__</code>) ืœื ื™ืชืงื™ื™ื, ื•ื”ืชื›ื•ื ื” <var>is_valid</var> ืœื ืชื•ื’ื“ืจ.<br> ื›ืฉื”ืœื•ืœืื” ืชื’ื™ืข ืœืงื•ื‘ื™ื™ื” 0 ื•ืชื ืกื” ืœื’ืฉืช ืœืชื›ื•ื ื” <var>is_valid</var>, ื ื’ืœื” ืฉื”ื™...
class Dice: def __init__(self, number): self.is_valid = (1 <= number <= 6) # ืœื ื—ื™ื™ื‘ื™ื ืกื•ื’ืจื™ื™ื dice_bag = [Dice(roll_result) for roll_result in range(7)] for dice in dice_bag: print(dice.is_valid)
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<span style="text-align: right; direction: rtl; float: right; clear: both;">ืกื™ื›ื•ื</span> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ื‘ืžื—ื‘ืจืช ื–ื• ืจื›ืฉื ื• ื›ืœื™ื ืœืขื‘ื•ื“ื” ืขื ืžื—ืœืงื•ืช ื•ืขืฆืžื™ื, ื•ืœื™ื™ืฆื•ื’ ืื•ืกืคื™ื ืฉืœ ืชื›ื•ื ื•ืช ื•ืคืขื•ืœื•ืช.<br> ื›ืœื™ื ืืœื• ื™ืขื–ืจื• ืœื ื• ืœืืจื’ืŸ ื˜ื•ื‘ ื™ื•ืชืจ ืืช ื”ืชื•ื›ื ื™ืช ืฉืœื ื• ื•ืœื™ื™ืฆื’ ื™ืฉื•ื™ื•ืช ืž...
import os class Path: def __init__(self, path): self.fullpath = path self.parts = list(self.get_parts()) def get_parts(self): current_part = "" for char in self.fullpath: if char in r"\/": yield current_part current_part = "" ...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
<span style="text-align: right; direction: rtl; float: right; clear: both;">ืชืจื’ื™ืœื™ื</span> <span style="text-align: right; direction: rtl; float: right; clear: both;">ืกืงืจื ื•ืช</span> <p style="text-align: right; direction: rtl; float: right; clear: both;"> ืžื—ืœืงืช ื”ืžื•ืฆืจ ื‘ืฆ'ื™ืงืฆ'ื•ืง ื”ื—ืœื™ื˜ื” ืœื”ื•ืกื™ืฃ ืคื™ืฆ'ืจ ืฉืžืืคืฉืจ ืœืžืฉืชืžืฉื™ื ืœื™ืฆ...
def cast_multiple_votes(poll, votes): for vote in votes: poll.vote(vote) bridge_question = Poll('What is your favourite colour?', ['Blue', 'Yellow']) cast_multiple_votes(bridge_question, ['Blue', 'Blue', 'Yellow']) print(bridge_question.get_winner() == 'Blue') cast_multiple_votes(bridge_question, ['Yellow...
week07/1_Classes.ipynb
PythonFreeCourse/Notebooks
mit
The command %matplotlib inline is not a Python command, but an IPython command. When using the console, or the notebook, it makes the plots appear inline. You do not want to use this in a plain Python code.
from math import sin, pi x = [] y = [] for i in range(201): x.append(0.01*i) y.append(sin(pi*x[-1])**2) pyplot.plot(x, y) pyplot.show()
04-basic-plotting.ipynb
jamesmarva/maths-with-python
mit
We have defined two sequences - in this case lists, but tuples would also work. One contains the $x$-axis coordinates, the other the data points to appear on the $y$-axis. A basic plot is produced using the plot command of pyplot. However, this plot will not automatically appear on the screen, as after plotting the dat...
from math import sin, pi x = [] y = [] for i in range(201): x.append(0.01*i) y.append(sin(pi*x[-1])**2) pyplot.plot(x, y, marker='+', markersize=8, linestyle=':', linewidth=3, color='b', label=r'$\sin^2(\pi x)$') pyplot.legend(loc='lower right') pyplot.xlabel(r'$x$') pyplot.ylabel(r'$y$') pyplot....
04-basic-plotting.ipynb
jamesmarva/maths-with-python
mit
Whilst most of the commands are self-explanatory, a note should be made of the strings line r'$x$'. These strings are in LaTeX format, which is the standard typesetting method for professional-level mathematics. The $ symbols surround mathematics. The r before the definition of the string is Python notation, not LaTeX....
from math import sin, pi, exp, log x = [] y1 = [] y2 = [] for i in range(201): x.append(1.0+0.01*i) y1.append(exp(sin(pi*x[-1]))) y2.append(log(pi+x[-1]*sin(x[-1]))) pyplot.loglog(x, y1, linestyle='--', linewidth=4, color='k', label=r'$y_1=e^{\sin(\pi x)}$') pyplot.loglog(x, y2, linestyle='...
04-basic-plotting.ipynb
jamesmarva/maths-with-python
mit
File browser
Image('images/lego-filebrowser.png', width='80%')
12-JupyterLab.ipynb
ellisonbg/talk-2015
mit
Terminal
Image('images/lego-terminal.png', width='80%')
12-JupyterLab.ipynb
ellisonbg/talk-2015
mit
Text editor (a place to type code)
Image('images/lego-texteditor.png', width='80%')
12-JupyterLab.ipynb
ellisonbg/talk-2015
mit
Output
Image('images/lego-output.png', width='80%')
12-JupyterLab.ipynb
ellisonbg/talk-2015
mit
์‚ฌ์ „ ์ œ์ž‘ Estimator <table class="tfo-notebook-buttons" align="left"> <td><a target="_blank" href="https://www.tensorflow.org/tutorials/estimator/premade"><img src="https://www.tensorflow.org/images/tf_logo_32px.png">TensorFlow.org์—์„œ ๋ณด๊ธฐ</a></td> <td><a target="_blank" href="https://colab.research.google.com/github/tens...
import tensorflow as tf import pandas as pd
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
๋ฐ์ดํ„ฐ์„ธํŠธ ์ด ๋ฌธ์„œ์˜ ์ƒ˜ํ”Œ ํ”„๋กœ๊ทธ๋žจ์€ ์•„์ด๋ฆฌ์Šค ๊ฝƒ์„ ๊ฝƒ๋ฐ›์นจ์žŽ๊ณผ ๊ฝƒ์žŽ์˜ ํฌ๊ธฐ์— ๋”ฐ๋ผ ์„ธ ๊ฐ€์ง€ ์ข…์œผ๋กœ ๋ถ„๋ฅ˜ํ•˜๋Š” ๋ชจ๋ธ์„ ๋นŒ๋“œํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค. Iris ๋ฐ์ดํ„ฐ์„ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•ฉ๋‹ˆ๋‹ค. Iris ๋ฐ์ดํ„ฐ์„ธํŠธ์—๋Š” ๋„ค ๊ฐ€์ง€ ํŠน์„ฑ๊ณผ ํ•˜๋‚˜์˜ ๋ ˆ์ด๋ธ”์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋„ค ๊ฐ€์ง€ ํŠน์„ฑ์€ ๊ฐœ๋ณ„ ์•„์ด๋ฆฌ์Šค ๊ฝƒ์˜ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์‹๋ฌผ ํŠน์„ฑ์„ ์‹๋ณ„ํ•ฉ๋‹ˆ๋‹ค. ๊ฝƒ๋ฐ›์นจ์žŽ ๊ธธ์ด ๊ฝƒ๋ฐ›์นจ์žŽ ๋„ˆ๋น„ ๊ฝƒ์žŽ ๊ธธ์ด ๊ฝƒ์žŽ ๋„ˆ๋น„ ์ด ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ๋ฌธ ๋ถ„์„ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” ๋ช‡ ๊ฐ€์ง€ ์ƒ์ˆ˜๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
CSV_COLUMN_NAMES = ['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth', 'Species'] SPECIES = ['Setosa', 'Versicolor', 'Virginica']
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
๊ทธ ๋‹ค์Œ, Keras ๋ฐ Pandas๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Iris ๋ฐ์ดํ„ฐ์„ธํŠธ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ๊ตฌ๋ฌธ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค. ํ›ˆ๋ จ ๋ฐ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด ๋ณ„๋„์˜ ๋ฐ์ดํ„ฐ์„ธํŠธ๋ฅผ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.
train_path = tf.keras.utils.get_file( "iris_training.csv", "https://storage.googleapis.com/download.tensorflow.org/data/iris_training.csv") test_path = tf.keras.utils.get_file( "iris_test.csv", "https://storage.googleapis.com/download.tensorflow.org/data/iris_test.csv") train = pd.read_csv(train_path, names=CS...
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์‚ฌํ•˜์—ฌ ๋„ค ๊ฐœ์˜ float ํŠน์„ฑ ์—ด๊ณผ ํ•˜๋‚˜์˜ int32 ๋ ˆ์ด๋ธ”์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
train.head()
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
๊ฐ ๋ฐ์ดํ„ฐ์„ธํŠธ์— ๋Œ€ํ•ด ์˜ˆ์ธกํ•˜๋„๋ก ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•  ๋ ˆ์ด๋ธ”์„ ๋ถ„ํ• ํ•ฉ๋‹ˆ๋‹ค.
train_y = train.pop('Species') test_y = test.pop('Species') # The label column has now been removed from the features. train.head()
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
Estimator๋ฅผ ์‚ฌ์šฉํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ฐœ์š” ์ด์ œ ๋ฐ์ดํ„ฐ๊ฐ€ ์„ค์ •๋˜์—ˆ์œผ๋ฏ€๋กœ TensorFlow Estimator๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ธ์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Estimator๋Š” tf.estimator.Estimator์—์„œ ํŒŒ์ƒ๋œ ์ž„์˜์˜ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค. TensorFlow๋Š” ์ผ๋ฐ˜์ ์ธ ML ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด tf.estimator(์˜ˆ: LinearRegressor) ๋ชจ์Œ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์™ธ์—๋„ ๊ณ ์œ ํ•œ ์‚ฌ์šฉ์ž ์ •์˜ Estimator๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฒ˜์Œ ์‹œ์ž‘ํ•  ๋•Œ๋Š” ์‚ฌ์ „ ์ œ์ž‘๋œ Estimator๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์‚ฌ์ „ ์ œ์ž‘๋œ Estimator๋ฅผ ๊ธฐ์ดˆ๋กœ Ten...
def input_evaluation_set(): features = {'SepalLength': np.array([6.4, 5.0]), 'SepalWidth': np.array([2.8, 2.3]), 'PetalLength': np.array([5.6, 3.3]), 'PetalWidth': np.array([2.2, 1.0])} labels = np.array([2, 1]) return features, labels
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
์ž…๋ ฅ ํ•จ์ˆ˜์—์„œ ์›ํ•˜๋Š” ๋Œ€๋กœ features ์‚ฌ์ „ ๋ฐ label ๋ชฉ๋ก์ด ์ƒ์„ฑ๋˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋ชจ๋“  ์ข…๋ฅ˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ๋ฌธ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ๋Š” TensorFlow์˜ Dataset API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. Dataset API๋Š” ๋งŽ์€ ์ผ๋ฐ˜์ ์ธ ๊ฒฝ์šฐ๋ฅผ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, Dataset API๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋Œ€๊ทœ๋ชจ ํŒŒ์ผ ๋ชจ์Œ์—์„œ ๋ ˆ์ฝ”๋“œ๋ฅผ ๋ณ‘๋ ฌ๋กœ ์‰ฝ๊ฒŒ ์ฝ๊ณ  ์ด๋ฅผ ๋‹จ์ผ ์ŠคํŠธ๋ฆผ์œผ๋กœ ๊ฒฐํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์˜ˆ์ œ์—์„œ๋Š” ์ž‘์—…์„ ๋‹จ์ˆœํ™”ํ•˜๊ธฐ ์œ„ํ•ด pandas ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ•˜๊ณ  ์ด ์ธ๋ฉ”๋ชจ๋ฆฌ ๋ฐ์ดํ„ฐ์—์„œ ์ž…๋ ฅ ํŒŒ์ดํ”„๋ผ์ธ์„ ๋นŒ๋“œํ•ฉ๋‹ˆ๋‹ค.
def input_fn(features, labels, training=True, batch_size=256): """An input function for training or evaluating""" # Convert the inputs to a Dataset. dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels)) # Shuffle and repeat if you are in training mode. if training: dataset ...
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
ํŠน์„ฑ ์—ด ์ •์˜ํ•˜๊ธฐ ํŠน์„ฑ ์—ด์€ ๋ชจ๋ธ์ด ํŠน์„ฑ ์‚ฌ์ „์˜ ์›์‹œ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์„ ์„ค๋ช…ํ•˜๋Š” ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. Estimator ๋ชจ๋ธ์„ ๋นŒ๋“œํ•  ๋•Œ๋Š” ๋ชจ๋ธ์—์„œ ์‚ฌ์šฉํ•  ๊ฐ ํŠน์„ฑ์„ ์„ค๋ช…ํ•˜๋Š” ํŠน์„ฑ ์—ด ๋ชฉ๋ก์„ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. tf.feature_column ๋ชจ๋“ˆ์€ ๋ชจ๋ธ์— ๋ฐ์ดํ„ฐ๋ฅผ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ๋งŽ์€ ์˜ต์…˜์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. Iris์˜ ๊ฒฝ์šฐ 4๊ฐœ์˜ ์›์‹œ ํŠน์„ฑ์€ ์ˆซ์ž ๊ฐ’์ด๋ฏ€๋กœ, ๋„ค ๊ฐœ์˜ ํŠน์„ฑ ๊ฐ๊ฐ์„ 32-bit ๋ถ€๋™ ์†Œ์ˆ˜์  ๊ฐ’์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋„๋ก Estimator ๋ชจ๋ธ์— ์•Œ๋ ค์ฃผ๋Š” ํŠน์„ฑ ์—ด ๋ชฉ๋ก์„ ๋นŒ๋“œํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํŠน์„ฑ ์—ด์„ ์ž‘์„ฑํ•˜๋Š” ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
# Feature columns describe how to use the input. my_feature_columns = [] for key in train.keys(): my_feature_columns.append(tf.feature_column.numeric_column(key=key))
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
ํŠน์„ฑ ์—ด์€ ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋œ ๊ฒƒ๋ณด๋‹ค ํ›จ์”ฌ ์ •๊ตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๊ฐ€์ด๋“œ์—์„œ ํŠน์„ฑ ์—ด์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์„ ์ฝ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋ธ์ด ์›์‹œ ํŠน์„ฑ์„ ๋‚˜ํƒ€๋‚ด๋„๋ก ํ•  ๋ฐฉ์‹์— ๋Œ€ํ•œ ์„ค๋ช…์ด ์ค€๋น„๋˜์—ˆ์œผ๋ฏ€๋กœ Estimator๋ฅผ ๋นŒ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Estimator ์ธ์Šคํ„ด์Šคํ™”ํ•˜๊ธฐ Iris ๋ฌธ์ œ๋Š” ๊ณ ์ „์ ์ธ ๋ถ„๋ฅ˜ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ๋‹คํ–‰ํžˆ๋„ TensorFlow๋Š” ๋‹ค์Œ์„ ํฌํ•จํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์‚ฌ์ „ ์ œ์ž‘๋œ ๋ถ„๋ฅ˜์ž Estimator๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์ค‘ ํด๋ž˜์Šค ๋ถ„๋ฅ˜๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์‹ฌ์ธต ๋ชจ๋ธ์„ ์œ„ํ•œ tf.estimator.DNNClassifier ๋„“๊ณ  ๊นŠ์€ ๋ชจ๋ธ์„ ์œ„ํ•œ tf.estimator.DNNLine...
# Build a DNN with 2 hidden layers with 30 and 10 hidden nodes each. classifier = tf.estimator.DNNClassifier( feature_columns=my_feature_columns, # Two hidden layers of 30 and 10 nodes respectively. hidden_units=[30, 10], # The model must choose between 3 classes. n_classes=3)
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
ํ›ˆ๋ จ, ํ‰๊ฐ€ ๋ฐ ์˜ˆ์ธกํ•˜๊ธฐ ์ด์ œ Estimator ๊ฐ์ฒด๊ฐ€ ์ค€๋น„๋˜์—ˆ์œผ๋ฏ€๋กœ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•ฉ๋‹ˆ๋‹ค. ํ›ˆ๋ จํ•œ ๋ชจ๋ธ์„ ํ‰๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ํ›ˆ๋ จํ•œ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์˜ˆ์ธก์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋ธ ํ›ˆ๋ จํ•˜๊ธฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด Estimator์˜ train ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•ฉ๋‹ˆ๋‹ค.
# Train the Model. classifier.train( input_fn=lambda: input_fn(train, train_y, training=True), steps=5000)
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
Estimator๊ฐ€ ์˜ˆ์ƒํ•œ ๋Œ€๋กœ ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ž…๋ ฅ ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•˜๋ฉด์„œ ์ธ์ˆ˜๋ฅผ ํฌ์ฐฉํ•˜๊ธฐ ์œ„ํ•ด lambda์—์„œ input_fn ํ˜ธ์ถœ์„ ๋ž˜ํ•‘ํ•ฉ๋‹ˆ๋‹ค. steps ์ธ์ˆ˜๋Š” ์—ฌ๋Ÿฌ ํ›ˆ๋ จ ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์นœ ํ›„์— ํ›ˆ๋ จ์„ ์ค‘์ง€ํ•˜๋„๋ก ๋ฉ”์„œ๋“œ์— ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค. ํ›ˆ๋ จํ•œ ๋ชจ๋ธ ํ‰๊ฐ€ํ•˜๊ธฐ ๋ชจ๋ธ์„ ํ›ˆ๋ จํ–ˆ์œผ๋ฏ€๋กœ ์„ฑ๋Šฅ์— ๋Œ€ํ•œ ํ†ต๊ณ„๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ ๋ธ”๋ก์€ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ์—์„œ ํ›ˆ๋ จํ•œ ๋ชจ๋ธ์˜ ์ •ํ™•๋„๋ฅผ ํ‰๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
eval_result = classifier.evaluate( input_fn=lambda: input_fn(test, test_y, training=False)) print('\nTest set accuracy: {accuracy:0.3f}\n'.format(**eval_result))
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
train ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ ํ˜ธ์ถœ๊ณผ ๋‹ฌ๋ฆฌ ํ‰๊ฐ€ํ•  steps ์ธ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. eval์— ๋Œ€ํ•œ input_fn์€ ๋‹จ ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ epoch๋งŒ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. eval_result ์‚ฌ์ „์—๋Š” average_loss(์ƒ˜ํ”Œ๋‹น ํ‰๊ท  ์†์‹ค), loss(๋ฏธ๋‹ˆ ๋ฐฐ์น˜๋‹น ํ‰๊ท  ์†์‹ค) ๋ฐ Estimator์˜ global_step ๊ฐ’(๋ฐ›์€ ํ›ˆ๋ จ ๋ฐ˜๋ณต ํšŸ์ˆ˜)๋„ ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. ํ›ˆ๋ จํ•œ ๋ชจ๋ธ์—์„œ ์˜ˆ์ธก(์ถ”๋ก )ํ•˜๊ธฐ ์šฐ์ˆ˜ํ•œ ํ‰๊ฐ€ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ›ˆ๋ จํ•œ ๋ชจ๋ธ์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ํ›ˆ๋ จํ•œ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ ˆ์ด๋ธ”์ด ์ง€์ •๋˜์ง€ ์•Š์€ ์ผ๋ถ€ ์ธก์ •์„ ๋ฐ”ํƒ•์œผ๋กœ ์•„์ด๋ฆฌ์Šค ๊ฝƒ์˜ ์ข…์„ ์˜ˆ์ธกํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ›ˆ๋ จ ๋ฐ ํ‰๊ฐ€...
# Generate predictions from the model expected = ['Setosa', 'Versicolor', 'Virginica'] predict_x = { 'SepalLength': [5.1, 5.9, 6.9], 'SepalWidth': [3.3, 3.0, 3.1], 'PetalLength': [1.7, 4.2, 5.4], 'PetalWidth': [0.5, 1.5, 2.1], } def input_fn(features, batch_size=256): """An input function for predi...
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
predict ๋ฉ”์„œ๋“œ๋Š” Python iterable์„ ๋ฐ˜ํ™˜ํ•˜์—ฌ ๊ฐ ์˜ˆ์ œ์— ๋Œ€ํ•œ ์˜ˆ์ธก ๊ฒฐ๊ณผ ์‚ฌ์ „์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ๋Š” ๋ช‡ ๊ฐ€์ง€ ์˜ˆ์ธก๊ณผ ํ•ด๋‹น ํ™•๋ฅ ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
for pred_dict, expec in zip(predictions, expected): class_id = pred_dict['class_ids'][0] probability = pred_dict['probabilities'][class_id] print('Prediction is "{}" ({:.1f}%), expected "{}"'.format( SPECIES[class_id], 100 * probability, expec))
site/ko/tutorials/estimator/premade.ipynb
tensorflow/docs-l10n
apache-2.0
Generating a click example Lets start by degradating some audio files with some clicks of different amplitudes
fs = 44100. audio_dir = '../../audio/' audio = es.MonoLoader(filename='{}/{}'.format(audio_dir, 'recorded/vignesh.wav'), sampleRate=fs)() originalLen = len(audio) jumpLocation1 = int(originalLen / 4.) jumpLocation2 = int(originalLen / 2.) jumpLocation3 = int(originalLen * 3...
src/examples/tutorial/example_clickdetector.ipynb
carthach/essentia
agpl-3.0
Lets listen to the clip to have an idea on how audible the clips are
Audio(audio, rate=fs)
src/examples/tutorial/example_clickdetector.ipynb
carthach/essentia
agpl-3.0
The algorithm This algorithm outputs the starts and ends timestapms of the clicks. The following plots show how the algorithm performs in the previous examples
starts, ends = compute(audio) fig, ax = plt.subplots(len(groundTruth)) plt.subplots_adjust(hspace=.4) for idx, point in enumerate(groundTruth): l1 = ax[idx].axvline(starts[idx], color='r', alpha=.5) ax[idx].axvline(ends[idx], color='r', alpha=.5) l2 = ax[idx].axvline(point, color='g', alpha=.5) ax[idx]...
src/examples/tutorial/example_clickdetector.ipynb
carthach/essentia
agpl-3.0
BigQuery Data If you have not gone through the KFP Walkthrough lab, you will need to run the following cell to create a BigQuery dataset and table containing the data required for this lab. NOTE If you already have the covertype data in a bigquery table at &lt;PROJECT_ID&gt;.covertype_dataset.covertype you may skip to ...
%%bash DATASET_LOCATION=US DATASET_ID=covertype_dataset TABLE_ID=covertype DATA_SOURCE=gs://workshop-datasets/covertype/small/dataset.csv SCHEMA=Elevation:INTEGER,\ Aspect:INTEGER,\ Slope:INTEGER,\ Horizontal_Distance_To_Hydrology:INTEGER,\ Vertical_Distance_To_Hydrology:INTEGER,\ Horizontal_Distance_To_Roadways:INTEG...
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Understanding the pipeline design The workflow implemented by the pipeline is defined using a Python based Domain Specific Language (DSL). The pipeline's DSL is in the pipeline_vertex/pipeline_vertex_automl_batch_preds.py file that we will generate below. The pipeline's DSL has been designed to avoid hardcoding any env...
%%writefile ./pipeline_vertex/pipeline_vertex_automl_batch_preds.py """Kubeflow Covertype Pipeline.""" import os from google_cloud_pipeline_components.aiplatform import ( AutoMLTabularTrainingJobRunOp, TabularDatasetCreateOp, ModelBatchPredictOp ) from kfp.v2 import dsl PIPELINE_ROOT = os.getenv("PIPELIN...
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Understanding the ModelBatchPredictOp When working with an AutoML Tabular model, the ModelBatchPredictOp can take the following inputs: * model: The model resource to serve batch predictions with * bigquery_source_uri: A URI to a BigQuery table containing examples to serve batch predictions on in the format bq://PROJEC...
%%bigquery CREATE OR REPLACE TABLE covertype_dataset.newdata AS SELECT * EXCEPT(Cover_Type) FROM covertype_dataset.covertype LIMIT 10000
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Compile the pipeline Let's start by defining the environment variables that will be passed to the pipeline compiler:
ARTIFACT_STORE = f"gs://{PROJECT}-kfp-artifact-store" PIPELINE_ROOT = f"{ARTIFACT_STORE}/pipeline" DATASET_SOURCE = f"bq://{PROJECT}.covertype_dataset.covertype" BATCH_PREDS_SOURCE_URI = f"bq://{PROJECT}.covertype_dataset.newdata" %env PIPELINE_ROOT={PIPELINE_ROOT} %env PROJECT={PROJECT} %env REGION={REGION} %env DATA...
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Let us make sure that the ARTIFACT_STORE has been created, and let us create it if not:
!gsutil ls | grep ^{ARTIFACT_STORE}/$ || gsutil mb -l {REGION} {ARTIFACT_STORE}
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Use the CLI compiler to compile the pipeline We compile the pipeline from the Python file we generated into a JSON description using the following command:
PIPELINE_JSON = "covertype_automl_vertex_pipeline_batch_preds.json" !dsl-compile-v2 --py pipeline_vertex/pipeline_vertex_automl_batch_preds.py --output $PIPELINE_JSON
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Note: You can also use the Python SDK to compile the pipeline: ```python from kfp.v2 import compiler compiler.Compiler().compile( pipeline_func=create_pipeline, package_path=PIPELINE_JSON, ) ``` The result is the pipeline file.
!head {PIPELINE_JSON}
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Deploy the pipeline package
aiplatform.init(project=PROJECT, location=REGION) pipeline = aiplatform.PipelineJob( display_name="automl_covertype_kfp_pipeline_batch_predictions", template_path=PIPELINE_JSON, enable_caching=True, ) pipeline.run()
notebooks/kubeflow_pipelines/pipelines/solutions/kfp_pipeline_vertex_automl_batch_predictions.ipynb
GoogleCloudPlatform/asl-ml-immersion
apache-2.0
Import raw data The user needs to specify the directories containing the data of interest. Each sample type should have a key which corresponds to the directory path. Additionally, each object should have a list that includes the channels of interest.
# -------------------------------- # -------- User input ------------ # -------------------------------- data = { # Specify sample type key 'wt': { # Specify path to data directory 'path': 'path\to\data\directory\sample1', # Specify which channels are in the directory and are of interes...
experiments/templates/TEMP-landmarks.ipynb
msschwartz21/craniumPy
gpl-3.0
We'll generate a list of pairs of stypes and channels for ease of use.
data_pairs = [] for s in data.keys(): for c in data[s]['channels']: data_pairs.append((s,c))
experiments/templates/TEMP-landmarks.ipynb
msschwartz21/craniumPy
gpl-3.0
We can now read in all datafiles specified by the data dictionary above.
D = {} for s in data.keys(): D[s] = {} for c in data[s]['channels']: D[s][c] = ds.read_psi_to_dict(data[s]['path'],c)
experiments/templates/TEMP-landmarks.ipynb
msschwartz21/craniumPy
gpl-3.0
Calculate landmark bins
# -------------------------------- # -------- User input ------------ # -------------------------------- # Pick an integer value for bin number based on results above anum = 25 # Specify the percentiles which will be used to calculate landmarks percbins = [50]
experiments/templates/TEMP-landmarks.ipynb
msschwartz21/craniumPy
gpl-3.0
Calculate landmark bins based on user input parameters and the previously specified control sample.
lm = ds.landmarks(percbins=percbins, rnull=np.nan) lm.calc_bins(D[s_ctrl][c_ctrl], anum, theta_step) print('Alpha bins') print(lm.acbins) print('Theta bins') print(lm.tbins)
experiments/templates/TEMP-landmarks.ipynb
msschwartz21/craniumPy
gpl-3.0
Calculate landmarks
lmdf = pd.DataFrame() # Loop through each pair of stype and channels for s,c in tqdm.tqdm(data_pairs): print(s,c) # Calculate landmarks for each sample with this data pair for k,df in tqdm.tqdm(D[s][c].items()): lmdf = lm.calc_perc(df, k, '-'.join([s,c]), lmdf) # Set timestamp for saving d...
experiments/templates/TEMP-landmarks.ipynb
msschwartz21/craniumPy
gpl-3.0
EEG forward operator with a template MRI This tutorial explains how to compute the forward operator from EEG data using the standard template MRI subject fsaverage. .. caution:: Source reconstruction without an individual T1 MRI from the subject will be less accurate. Do not over interpret act...
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr> # Joan Massich <mailsik@gmail.com> # Eric Larson <larson.eric.d@gmail.com> # # License: BSD-3-Clause import os.path as op import numpy as np import mne from mne.datasets import eegbci from mne.datasets import fetch_fsaverage # Download fsa...
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause
Load the data We use here EEG data from the BCI dataset. <div class="alert alert-info"><h4>Note</h4><p>See `plot_montage` to view all the standard EEG montages available in MNE-Python.</p></div>
raw_fname, = eegbci.load_data(subject=1, runs=[6]) raw = mne.io.read_raw_edf(raw_fname, preload=True) # Clean channel names to be able to use a standard 1005 montage new_names = dict( (ch_name, ch_name.rstrip('.').upper().replace('Z', 'z').replace('FP', 'Fp')) for ch_name in raw.ch_names) raw.rename_chann...
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause
Setup source space and compute forward
fwd = mne.make_forward_solution(raw.info, trans=trans, src=src, bem=bem, eeg=True, mindist=5.0, n_jobs=None) print(fwd)
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause
From here on, standard inverse imaging methods can be used! Infant MRI surrogates We don't have a sample infant dataset for MNE, so let's fake a 10-20 one:
ch_names = \ 'Fz Cz Pz Oz Fp1 Fp2 F3 F4 F7 F8 C3 C4 T7 T8 P3 P4 P7 P8 O1 O2'.split() data = np.random.RandomState(0).randn(len(ch_names), 1000) info = mne.create_info(ch_names, 1000., 'eeg') raw = mne.io.RawArray(data, info)
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause
Get an infant MRI template To use an infant head model for M/EEG data, you can use :func:mne.datasets.fetch_infant_template to download an infant template:
subject = mne.datasets.fetch_infant_template('6mo', subjects_dir, verbose=True)
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause
It comes with several helpful built-in files, including a 10-20 montage in the MRI coordinate frame, which can be used to compute the MRI<->head transform trans:
fname_1020 = op.join(subjects_dir, subject, 'montages', '10-20-montage.fif') mon = mne.channels.read_dig_fif(fname_1020) mon.rename_channels( {f'EEG{ii:03d}': ch_name for ii, ch_name in enumerate(ch_names, 1)}) trans = mne.channels.compute_native_head_t(mon) raw.set_montage(mon) print(trans)
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause
There are also BEM and source spaces:
bem_dir = op.join(subjects_dir, subject, 'bem') fname_src = op.join(bem_dir, f'{subject}-oct-6-src.fif') src = mne.read_source_spaces(fname_src) print(src) fname_bem = op.join(bem_dir, f'{subject}-5120-5120-5120-bem-sol.fif') bem = mne.read_bem_solution(fname_bem)
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause
You can ensure everything is as expected by plotting the result:
fig = mne.viz.plot_alignment( raw.info, subject=subject, subjects_dir=subjects_dir, trans=trans, src=src, bem=bem, coord_frame='mri', mri_fiducials=True, show_axes=True, surfaces=('white', 'outer_skin', 'inner_skull', 'outer_skull')) mne.viz.set_3d_view(fig, 25, 70, focalpoint=[0, -0.005, 0.01])
dev/_downloads/1242d47b65d952f9f80cf19fb9e5d76e/35_eeg_no_mri.ipynb
mne-tools/mne-tools.github.io
bsd-3-clause