Dynamic programming (4) Example

Consider a simple consumption-saving model, where action (a) is defined by the amount of savings each period, state (s) defined by the current stock, reward be the utility which depends on consumption (c=s-a). Suppose that state is updated where the output is drawn from a uniform distribution on {0, . . . , B}. Let the global upper bound of storage be M. State space State space is \(n = M+B+1\) dimension....

April 15, 2023 · 3 min · 604 words · Me

DataFrames.jl (2)

Taking a Subset We can subset a dataframe using index. For example we can subset specific columns and rows by following codes. # column subset (subset df to only include column A and C) df[:, [:A, :C]] # row subset (subset df to only include 1st, 3rd, and 5th rows) df[[1,3,5], :] We could also use some selectors such as Not, Between, Colsand All. Following code removes columns whose names match r"x"....

April 12, 2023 · 1 min · 152 words · Me

DataFrames.jl (1)

Create dataframe To create a dataframe, simply use DataFrame function after loding DataFrames.jl. Following code produces a dataframe composed of three variables, A, B, and C, each of which has 500 rows. Each row of column A increments by 2 starting from integer 1. Column B repeats 50 times of each integer starting from 1. Coumn C lists integers from 1 to 500. using DataFrames df = DataFrame(A=1:2:1000, B= repeat(1:10, inner=50), C= 1:500) first, last The first and last functions act as head and tail function in R, which allow us to view the first or the last couple of rows of the dataset....

April 11, 2023 · 2 min · 236 words · Me

Dynamic programming (3) Discrete DPs

Let \(s_t\) denotes the state variable, \(a_t\) denotes the action, \(\beta\) denotes a discount factor. Note that \(r(a_t, s_t)\) can be interpreted as a current reward that is a function of the current action and current state.

April 10, 2023 · 1 min · 37 words · Me

Dynamic programming (2) Rewards

Rewards The goal of the agent is to maximize the cumulative sum of the rewards of the long-run. The rewards could be arbitrarily chosen number that summarizes how one wants the agent to behave under specific state, action, and subsequent state. The rewards function, formally represented by \(R(s)\) or \(R(s,a)\), or \(R(s, a, s^\prime)\) can depend on current state, the subsequent state as well as the action taken by the agent taken in the current state....

April 9, 2023 · 2 min · 387 words · Me

Some random thoughts

Went to Epik High concert. Can’t forget the sound, the vibe, the exhilarating vibration of bass that I felt from the tip of my foot. Take some time to enjoy life. Find something you think is worth spending your time and energy on. And do that more often.

April 7, 2023 · 1 min · 48 words · Me

Dynamic programming (1) MDP

The agent and the environment In finite Markov Decision Process (MDP), we have three sets, a set of states, a set of actions, and a set of rewards. The learner or decision maker is called agent and the outside system that the agent interacts with is called environment. Everyperiod, the agent takes actions and correspondingly the environment reacts to produce new states to the agent. Each period, the environment presents \(S_t\) from a set \( S\)....

April 6, 2023 · 2 min · 421 words · Me

Map and broadcast

Map map(f, c...) applies function f to each element of collection c that enter as the the second argument of the map function. Below two lines of codes produce same output. This means that map also acts as a for loop. map(x->x+2, 1:10) [ x + 2 for x=1:10] Output: 10-element Vector{Int64}: 3 4 5 6 7 8 9 10 11 12 The function that enters the first argument of map could take multiple arguments; it could be more than one argument....

April 5, 2023 · 2 min · 262 words · Me

Comprehension

Comprehensions works similar to for loop except that it can be expressed into a single line. For example, below will iterate the process of summing three variables that takes different integer in a range of 1 and 3. This will produce 27 different cases each of which will be stored in 3x3x3 array. [ i + j + k for i=1:3, j=1:3, k=1:3 ] Output: 3×3×3 Array{Int64, 3}: [:, :, 1] = 3 4 5 4 5 6 5 6 7 [:, :, 2] = 4 5 6 5 6 7 6 7 8 [:, :, 3] = 5 6 7 6 7 8 7 8 9

April 4, 2023 · 1 min · 107 words · Me

Optimization Using Julia

We exploreOptim package. We will first load Optim and Gadfly package. Optim is to use optimize and Gadfly is to plot a graph. Univariate Here, I create a quartric function, a fourth-degree polynomial to test optimize function. From the graph that plots the quartric function, the minimum of the function should lie within the range of 0 and 5. using Optim, Gadfly # univariate f1(x) = (x-1)*(x-2)*(x-3)*(x-4) plot(1:10, x-> f(x)) Let’s test optimize....

April 3, 2023 · 2 min · 291 words · Me

What job might not be replaceable by AI?

To answer this questions, I needed to ask myself which fields are difficult to imagine humans out of the picture. This led me to consider fields that place value on the dynamic nature of imperfections. Sports I believe that the primary reason for using artificial intelligence is to maximize efficiency and effectiveness. By default, they strive for perfection by optimizing the value function and finding roots as quickly as possible. Additionally, robots don’t have biological limits, unlike humans (Note: I’m not using “robots” and “artificial intelligence” interchangeably, but rather, referring to artificial intelligence placed on non-human objects, which I’ll call “robots” hereinafter....

April 2, 2023 · 2 min · 320 words · Me

Modules in Julia

Modules vs Packages Modules are used to group multiple functions and definitions together. Packages group multiple modules together with various metadata. Create a custom module Open up a new .jl file to create your own module. Here I named the file “testModule.jl”. In the file, one can group functions and/or other definitions together. Two functions are grouped by the module myModule. Only myfunction is exported. module myModule export myfunction function myfunction() println("Hello, friend") end function mysecretfunction() println("Hello, secret friend") end end Load modules To load modules, use either using or import....

April 1, 2023 · 1 min · 154 words · Me

For loop, RData, filter, and wsample in Julia

Struct Constructors are functions that create new objects. In Julia, constructors can also be used as functions when applied to an argument tuple. This can be done using struct syntax. struct is a kind of type in Julia that is specified as a name and a set of fields. It looks similar to JSON representation without specific values assigned. struct Foo bar baz end # Note that when Foo is served as a constructor function, # each element of the argument tuple is used as a value for the ordered fields....

March 31, 2023 · 2 min · 411 words · Me

Basics of Julia

Basics In Julia, the name of the variables can be very flexible; we can use Unicode as a variable name. You can also use Unicode math symbols as variable names. To do so, type a backslash followed by the Latex Symbol; then press tab to autocomplete. For example, to type the alpha symbol, simply type “\alpha” followed by tab. # Assigning values to different types to variables x = 1 안녕하세요 = 2 y = "안녕하세요" # We can use Unicode math symbols by backslash Latex symbol followed by tab....

March 30, 2023 · 4 min · 651 words · Me

Perfect Prediction?

Economics has been long striving to predict our behaviors. Unlike natural science, social science deals with far more noise. There’s always noise and error present, not only from the technical errors that come from sampling and other sources, but also from the inherent inconsistencies and occational irrationality of people. This is perhaps why we need an economist, to predict the future that is created by the aggregate of these unpredictability, in order to better prepare ourselves for the uncertainties....

August 30, 2021 · 2 min · 290 words · Me

0 min · 0 words · Me