<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Albert Su]]></title><description><![CDATA[Just a kid looking to make it]]></description><link>https://albertsu.netlify.app/</link><generator>GatsbyJS</generator><lastBuildDate>Fri, 14 Jul 2023 05:50:46 GMT</lastBuildDate><item><title><![CDATA[Showerthoughts]]></title><description><![CDATA[Musings on Interpersonal Interactions]]></description><link>https://albertsu.netlify.app//posts/misc/showerthoughts</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/misc/showerthoughts</guid><pubDate>Fri, 21 Nov 2025 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;useful-stuff&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#useful-stuff&quot; aria-label=&quot;useful stuff permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Useful stuff&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Get people to contribute to an idea and they will be more likely to accept it. Studies show that it doesn’t take that much involvement in the creative process to get people to take possession of a proposed plan.&lt;/li&gt;
&lt;li&gt;Easy way to get people to like you
Them: Tell me about yourself?
You: I did blah blah blah…, what about you?
Them: Blah Blah Blah
You: Wow, that’s so hard!&lt;/li&gt;
&lt;li&gt;Why not faster? Why can’t we build this startup/finish this homework/learn this skill faster?&lt;/li&gt;
&lt;li&gt;If you really want to connect with someone, take them for a long, scenic walk. Not being face to face takes some of the pressure off, and the scenery puts you in the right mood to open up.&lt;/li&gt;
&lt;li&gt;If you haven’t used your voice in a while (sleeping, lonely, etc) and suddenly need to take a phone call, hum for a few seconds prior. Your vocal cords won’t let you down.&lt;/li&gt;
&lt;li&gt;If you want to offer a deep and memorable compliment, ask someone how they did something. It gives them the opportunity to tell their story, and shows your genuine interest.&lt;/li&gt;
&lt;li&gt;When complementing people, always compliment them on something they have earned, not something they have.&lt;/li&gt;
&lt;li&gt;When you’re leading a conversation, it’s very good to invite other people who might be more quiet by asking them what they think or joking with them.&lt;/li&gt;
&lt;li&gt;Fully commit to friendly gestures, such as high fives, back pats, shoulder touches. Fully committing matters as it shows more confidence but also helps with being more trustworthy.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;not-useful-stuff&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#not-useful-stuff&quot; aria-label=&quot;not useful stuff permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Not Useful stuff&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Several times in life I’ve cold called a company to confirm my interview time. I didn’t have one prior to my call, but in their confusion and inability to even find my resume I’ve managed to secure an interview about four out of five times. Twice I’ve gotten the job.&lt;/li&gt;
&lt;li&gt;When smoking meats in a barbecue, instead of using wood smoke, use a juul for extra flavor.&lt;/li&gt;
&lt;li&gt;For group interviews, have the candidate play a level of overcooked to see how well they work as a team and respond to stress&lt;/li&gt;
&lt;li&gt;Things that are complete are completed, things that are incomplete are incomplete&lt;/li&gt;
&lt;li&gt;Denero’s first lecture(Intro to Computer Science) was very impressive because he did some playing around with numbers while teaching us how to use + - * and /. He kept making small examples ie 4+3 is 7 to show what the operators where, something that we naturally know how to use. However, he later created another expression 1+2*3+4/5… which ended up evaluating to 2019&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;longer-stuff&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#longer-stuff&quot; aria-label=&quot;longer stuff permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Longer stuff&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Time Management:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;My advice might be different than what you are expecting but try to think of your problem from a different angle. Let me explain: you’re currently seeing your problem as how to optimize your internship search but you’ve implicitly assumed that you’re going to dedicate your time primarily to school and secondarily to finding an internship.&lt;/li&gt;
&lt;li&gt;I would suggest freeing up 100% of your time as a thought experiment and then only take actions that contribute to your goal. If your goal is grad school, you might need to keep your GPA up a bit higher, and that means you can’t do as many interesting projects and look for internships. However, if your goal is a job after graduation then think of your resume as your primary goal, and if your classes align with that, spend more time engaging with those classes. If they don’t, then miss an assignment or just do the main parts and sacrifice the points.&lt;/li&gt;
&lt;li&gt;For me, once I saw school as secondary and my projects and portfolio as primary, I found I was more interested in my coursework because I saw it as something that would help me solve my real problems, and I absolutely blew away the projects I was assigned because I didn’t just care to fulfill the requirements, but also to present the projects as impressive and relevant to industry on my website and github.&lt;/li&gt;
&lt;li&gt;Furthermore, I found that this method keeps me much more interested, which is a more correlated with success and retention, and so I became much more productive, and was able to still keep up my other extra curricular commitments. YMMV.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;On meaning: One always finds one’s burden again.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Camus uses Sisyphus as a metaphor to describe our absurd existence. Like Sisyphus, we are in a constant cycle of striving for purpose and discovering that it is all devoid of meaning. In Sisyphus’ case, the gods condemned him to this task with the idea that all his efforts will be futile, the punishment being that he puts forward a monumental effort for nothing. However, it is not up to the gods to determine what gives Sisyphus purpose. Sisyphus can find meaning in this task if he so chooses, and by finding meaning in this task, he revolts against the gods who want him to suffer. Likewise, we are faced with the Absurd; a universe seemingly without objective meaning. By responding to this with our own subjective meaning, we revolt against the Absurd.&lt;/li&gt;
&lt;li&gt;“The struggle towards the heights is enough to fill a man’s heart. One must imagine Sisyphus happy.”&lt;/li&gt;
&lt;li&gt;I don’t know if I necessarily believe that Sisyphus has to be HAPPY to defy the gods and find purpose, but I think the idea Camus is trying to convey is that nothing/nobody gets to decide what your purpose is. And even though the universe is without meaning, that doesn’t mean that we have to live meaningless lives.&lt;/li&gt;
&lt;li&gt;The way I interpret the quote in the picture is: at the beginning of every day, we are all too aware of the burdens we will face, and the struggle we are about to undergo. No matter what, we will always strive for something bigger than ourselves. As we accomplish one thing, another goal replaces it, and we are constantly struggling to be complete. By recognizing how difficult life is, and how we are always incomplete in some sense, we can live in rebellion to the negative feelings that keep us from moving forward. We voluntarily take on the burden of life, knowing that burden will never fully be lifted. Why? Camus sees that struggle as purpose. And whatever reason you subjectively have&lt;/li&gt;
&lt;li&gt;&lt;em&gt;“I leave Sisyphus at the foot of the mountain. One always finds one’s burden again.”&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Personal Project Ideas]]></title><description><![CDATA[Ideas for fun projects]]></description><link>https://albertsu.netlify.app//posts/misc/personal-project-ideas</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/misc/personal-project-ideas</guid><pubDate>Mon, 10 Nov 2025 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;completion-time-10-years&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#completion-time-10-years&quot; aria-label=&quot;completion time 10 years permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Completion Time: 10 years&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;The social dilemma: No financial incentive for companies to keep gathering data. Make a tax on data or a way to track how much data companies gather&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;completion-time-1-year&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#completion-time-1-year&quot; aria-label=&quot;completion time 1 year permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Completion Time: 1 year&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;ShopLYFT - Like LYFT but for groceries except instead of paying for the groceries, you just walk out of the store with them(all orders must be $900 or less)&lt;/li&gt;
&lt;li&gt;List of source code for ethereum projects that allows you to query for specific exploits, ie keccak(msg.data) not being the same in every transaction&lt;/li&gt;
&lt;li&gt;Cal clone club - clone the startups/large companies and perform the same service without making any profits&lt;/li&gt;
&lt;li&gt;Blockchain that keeps track of pollution, forces people to pay on their agreements, using IOT devices that track pollution.&lt;/li&gt;
&lt;li&gt;Use crypto economics like proof of work/stake to make a review system that cannot be bought like yelp, amazon reviews, rotten tomatoes&lt;/li&gt;
&lt;li&gt;U2f security key for in person use ie yubikey for houses&lt;/li&gt;
&lt;li&gt;Delivery drivers in doordash need to wait to drop off package. Use public key private key cryptography to let them open a box to drop package in&lt;/li&gt;
&lt;li&gt;Dao owning football/sports team&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;completion-time-1-month&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#completion-time-1-month&quot; aria-label=&quot;completion time 1 month permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Completion Time: 1 month&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;You should build a smart contract that allows illegal immigrants to pay the people that smuggle them across the border only when they actually cross the border&lt;/li&gt;
&lt;li&gt;Create a discord server where you can ask questions and get paid in crypto using discord commands for answering technical questions&lt;/li&gt;
&lt;li&gt;Quiz pop up questions as google chrome extension for youtube lecture videos&lt;/li&gt;
&lt;li&gt;Box next to soccer field or basketball court that tracks the number of people there to predict when to go to pickup at optimal time&lt;/li&gt;
&lt;li&gt;Optimal size for bug bounty research&lt;/li&gt;
&lt;li&gt;Short Quizzes at the end of articles to test knowledge/for fun&lt;/li&gt;
&lt;li&gt;Take series 66 exam for fun lol&lt;/li&gt;
&lt;li&gt;Create match highlights(soccer, basketball) based on number of comments in live chat&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;completion-time-1-week&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#completion-time-1-week&quot; aria-label=&quot;completion time 1 week permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Completion Time: 1 week&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Write up an article on people’s ama, for example this one: &lt;a href=&quot;https://www.teamblind.com/post/Started-in-VC-right-out-of-undergrad--AMA-4pN5cL2r&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.teamblind.com/post/Started-in-VC-right-out-of-undergrad—AMA-4pN5cL2r&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Use student loan pricing data from places like SoFi to create school rankings&lt;/li&gt;
&lt;li&gt;Scaling Gracepoint, article on how they did it&lt;/li&gt;
&lt;li&gt;Pretend to be a student to ask recruiters to rank most prestigious company, most prestigious school as a part of a survey&lt;/li&gt;
&lt;li&gt;Article on zkproofs &lt;a href=&quot;https://www.youtube.com/watch?v=fOGdb1CTu5c&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.youtube.com/watch?v=fOGdb1CTu5c&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Reading List]]></title><description><![CDATA[List of books to read]]></description><link>https://albertsu.netlify.app//posts/misc/reading-list</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/misc/reading-list</guid><pubDate>Mon, 10 Nov 2025 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;to-read&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#to-read&quot; aria-label=&quot;to read permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;To Read&lt;/h1&gt;
&lt;p&gt;The green book - gaddafi
Network State
New Lombard Street
Lombard Street
End of Finance
Global History - Nature of Money
&lt;a href=&quot;https://www.seriouseats.com/the-food-lab-answers-questions-about-food-science&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.seriouseats.com/the-food-lab-answers-questions-about-food-science&lt;/a&gt;
Alchemy of Finance
Outsiders: Eight Unconventional CEOs
Principles - Ray Dalio
More Money than God&lt;/p&gt;
&lt;h1 id=&quot;read&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#read&quot; aria-label=&quot;read permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Read&lt;/h1&gt;
&lt;p&gt;Never Split the difference
All you need for college Admissions - &lt;a href=&quot;https://nikhilsardana.github.io/guide.pdf&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://nikhilsardana.github.io/guide.pdf&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kinesis Labs]]></title><description><![CDATA[Problems encountered when running Kinesis]]></description><link>https://albertsu.netlify.app//posts/kinesis-labs/misc-problems</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/kinesis-labs/misc-problems</guid><pubDate>Mon, 20 Jan 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This one really sucks. It was a series of unfortunate mistakes that led to a multinational company repeatedly issuing DMCA takedown notices on our website.&lt;/p&gt;
&lt;p&gt;Timeline of Events: 1. We create Kinesis Labs, a stableswap on Evmos. 2. I personally didn’t know it at the time, but Kinesis is based off a character from Maplestory - named Kinesis. Maplestory is owned by Nexon Corporation 3. When we published the site, we bought the domain kinesislabs.co(this is fine, there are tons of products out there named Kinesis). The problem is that we used a picture off google images of the Maplestory Kinesis. 4. This image was only a temporary placeholder while we commissioned art(for 3k USD -_-) from our artist. What they drew is pretty distinctive from the Maplestory Kinesis. 5. At the same time, we received two messages from someone in Nexon Corportaion in telegram and twitter asking us if we knowingly infriged copyright laws. Obviously, we ignore these messages, as we get tons of similar spam every day.
a. Side Note: I feel like even if we did respond to these messages, it wouldn’t have done much good since it seems like the reporter already filed a complaint to Nexon and was trying to get a confession out of us. He wasn’t trying to help us make sure our website was compliant.
b. Side Side Note: We looked at this guy’s twitter profile. From what we’ve gathered, this is lieterally your average defi user who happened to follow us because they were interested in our project. They then decided to report our website to their employer/ 6. We ignore the message again, oops, and we receive notice of a DMCA on Netlify. If we don’t respond, they will take down our site in 7 days. 7. The notice was extremely incomplete of course, the pictures they linked were no longer on our site, so we draft a reply. We also asked our friends for advice, most said we were fine, and one of our friends actually put us in contact with a law firm. We didn’t immediately engage with the firm because it was expensive and we did not raise any money, so all legal fees would come from our own pockets. 8. We draft a reply, under my name, telling them the links they sent were invalid and no longer on our side. For some legal reason, drafting a reply opens you personally up to legal liability. Of course, this does nothing - apparently we filed the response in an incorrect format to AWS. 9. We migrate to Vercel in the meantime. We then get another DMCA on vercel - even though they linked the webpage from Netlify. 10. We draft up a response to vercel, the problem right now isn’t just the legal issues but that fact that these hosting websites take own our site immediately upon receiving a DMCA notice, not after the dispute has been disputed.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Things to do when...]]></title><description><![CDATA[Reflections on Life So Far]]></description><link>https://albertsu.netlify.app//posts/misc/Things-to-do</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/misc/Things-to-do</guid><pubDate>Sun, 10 Nov 2024 23:46:37 GMT</pubDate><content:encoded>&lt;p&gt;What are my strengths?
- No forethought and no when to quit, but has drive to put something out into the world
What do I need to improve on?
- People skills could be improved
- Very profit driven
What do I want in a job?
- I want to work like a dog. I want to work at a place where people are encouraged to sleep under their desks and pull all-nighters. I’m not sure why I’m like this, but I’ve noticed that I can’t sit too still and do nothing, I’m always building side projects(Kinesis, Stardust, Klade) or working for Risk Harbor/Yoz/0xFoobar during school and my internships - I feel like something is missing if I don’t have a project I can throw myself in. Maybe things will change, but I would have to wait and see and I think it would be more fun this way in the first place. (want to prove something to myself)
- Somewhere with high upside and is has a long term vision
- I want to work with smart, brutally honest, and quick learners. I want the people I work with the call me out when I make mistakes.
- In person
About Me
- Basic stats + story of how you grew up
○ In my early life up to the end of middle school, I honestly don’t remember doing much besides going to school, going to a Chinese afterschool, and playing a bunch of different sports(cross-country, track, basketball, soccer). I also went to church and did a bunch of Boy Scouts related stuff which is honestly pretty underrated - I don’t think there are any other organizations that let a 14 year old plan a 12 day trip to the middle of the New Mexico Desert whilst having to worry about transportation, airfare, gear, and keeping everyone alive lol. I also played this one video game called Realm of the Mad God, where you go around and kill enemies with other players. This lowkey taught me a decent bit about economics - supply and demand, liquidity, stores of value, how to scam people, etc,
○ During high school, I was lucky enough that my friends in middle school knew a bit more of how one is “supposed to” play high school, so I did clubs like DECA and FBLA at their recommendations. I actually made a few good friends in FBLA and DECA, mostly because I went super try hard. Lynbrook was really good at this event called Parliamentary Procedure, which was essentially a set of rules that maximize the efficiency of organizational meetings, most commonly used by stuff like the English Parliament and the US Congress. Unfortunately, this meant memorizing this really old book called Roberts Rules of Order which was 1100+ pages. We also memorized the exact wording for each of our roleplays which was doubly painful since there were probably a few hundred prompts and a few hundred different responses to these prompts. Luckily, I’m still pretty good friends with one of the people I did Parliamentary Procedure with so I guess it was worth it in the end. It also showed me that you can control the outcome of seemingly random “businessy” competitions where you are judged on more subjective indicators. Before, I thought judging for business case competitions was super random and arbitrary when in fact you could break down what the judges wanted to see, even when the judges themselves didn’t know exactly what they wanted to see. (We also won 1st in the section, 2nd in the state, and 3rd at Nationals lol using tricks like these) Unfortunately, I didn’t figure out DECA until senior year, but you can just read the DECA tips section if you want to win at DECA.
I honestly don’t have many key people in my life that I can recall influencing me directly, rather, it’s probably been people influencing me indirectly via osmosis. I’m guessing that my academic success was at least partially influenced by the people around me, my parents had some influence but I think it was mostly my peers that drove me to do the things that one needs to do to become “successful”. For example, I only learned about SAT prep from my peers, not my parents. I needed to find my own free SAT classes online and practice tests which I would probably not have done without my friends pressuring me by comparing my SAT scores to theirs. When my friends started taking AP Classes, I felt like I needed to keep up and ended up taking 10 APs over 2 years, self-studying most of them. I’m super privileged - grew up in the Bay Area at a good to elite high school without having to worry about anything but school and my interests - yet my parents never pushed me to do better in school(only had a 3.8 uw gpa) or to do cookie cutter extracurriculars(they were fine with me quitting piano and band)
- Past professional life
○ I think doing computer science would have been much less fun without my peers. We managed to gamify the worst part of computer science, the job and internship hunt. Additionally, classes are hard but being able to bond through shared trauma is another huge benefit of the Berkeley computer science curriculum.
○ I think one interesting thing is how I ended up working in crypto. As a freshman, I tried to do basically everything. I tried Berkeley clubs(got rejected from all of them), worked in a chemistry research lab to see if things other than computer science were worth doing, did research through the haas neuroeconomics labs to see what applied computer science was like, and took as many classes as I could. However, nothing really interested me, since the cool things one could do in each of these programs were limited by my experience. Thus, I needed to find a field where one could make major contributions without having any experience and a nascent field was best for this.
○ I quit my haas neuroeconomic lab with one of my friends that also worked there and started building stuff for crypto. I worked on that project for a bit over a year and eventually went and joined a crypto startup that I found on discord after the project died. Afterward, I ghosted that startup to work on my own project again. I just find it super interesting that all of these events couldn’t really have been predicted from one timestep back. In high school, there was no way I could have predicted that I would be working in a research lab at a business school. While working at the research lab, I had no idea my next step would be to work on something in crypto. And while working on our project, I had no idea I would leave that to become an employee of another crypto startup.
○ In the meantime, I also worked one summer at the NSA. Originally, I wanted to work there since I wanted to know a few random things like what crypto systems does the government know how to break and what parts of the US government are controlled by who but at the end of the day I just thought it was really cool and that it was an opportunity I would never have again. I don’t think I learned too much technically, it was more high level architecture, what is possible and not possible, and a lot of systems reliability engineering principles(read the google SRE book if you want to know what I did during this internship). Another thing I took away was the ability to move to a new city and establish routines, find friends, and generally survive. I met some really cool people at my apartment, such as a Harvard lawyer who works at the white house(ex. SEC) and a basketball trainer who used to train Jalen Smith(Indiana Pacers)
○ The summer afterwards, I did an internship at Coinbase which looking back, I shouldn’t have done. It was mostly grunt solidity, typescript, and Go work that wasn’t very fun and everyone there was super depressed since 18% of the company was laid off on the second day of work and coinbase wasn’t doing anything cool that I thought it would. However, this gave me time to go to Seattle for a month and meet some pretty cool people like the Eigenlayer team and Thomas.
○ Finally, I did a lot of stuff in crypto: see below for more info.
- Any life goals?
○ Still figuring this out
- Do you do anything for fun?
○ Play basketball/soccer, sports where there is some level of teamwork involved and that forces you to immerse yourself in that game.
○ Some other random stuff I’ve tried recently that I’ve enjoyed:
§ Writing - both technical content as well as reflections like this. Weird since I hated writing in middle and high school
§ Climbing - both outdoor and indoor are really fun, but I need someone with experience to take me outdoors and indoors is too expensive/too much of a commitment to buy a pass
§ Skiing/Snowboarding - incredibly fun and expensive sport, however, I kinda get bored skiing/snowboarding since after a while even the double blacks don’t provide the type of challenge and fear I crave. Maybe teaching others is a good alternative that might make things more fun?
§ Chess - mostly as a crutch for short term entertainment instead of playing more traditional video games
§ Going to Hackathons - I feel like suffering together for long periods of time is the quickest way to make friends, and as such, hackathons are a perfect place to do so. Also, usually prizes are pretty decent for the amount of work you put in and I think I’ve figured out a way to win the game of hackathons.
§ Hiking/Outdoors stuff - Vanilla hiking is kinda boring, unless the scenery is crazy(unlikely since I’ve seen most types of views). One thing I realize I enjoy while hiking is peer pressuring my friends to go swimming in the nearest lake/river on the hike, it makes things seem more visceral and real.
§ Finding Free Food - Hillel, VC dinners, club events, finding free food not only gives you free food, but also an excuse to do whatever the free food providers are doing, which is usually something new.
§ Traveling - But am I just traveling since I’m running away from my problems or is there something I’m chasing after? Traveling is lowkey pretty fun though, and I feel like no matter where I go I know someone there or I can make friends pretty quickly if I’m by myself which makes traveling so much more fun. Also, ever since I stopped grinding at life, I feel like traveling is 10x more fun since there isn’t really work stuff I’m always thinking about
- When were you most happy?
○ Doing dumb stuff with friends, such as going to a random barber in Mexico and telling them to cut it however they thought looked good.
○ Also, it sounds weird but sometimes I’ll really enjoy coding. I vividly remember being really happy while working on the Penn blockchain hackathon project
- Who do you respect? If no one, are there parts of anyone you respect?
○ I respect anyone who has ever built anything. Just the willingness to build something and bringing it into the world is something I wish more people would do
○ Also, I really respect anyone that went through difficulties in their childhood to get to where they are today&lt;/p&gt;
&lt;p&gt;Crypto things I’ve done in the past
From most recent to least recent&lt;/p&gt;
&lt;p&gt;Stardust Built a p2p lending platform for ETH San Francisco. Honestly, this idea has been floating around in me and a friend’s head - here’s a brief description:&lt;/p&gt;
&lt;p&gt;Our initial focus is semi-locked tokens - strong liquidity for the underlying, despite these derivative tokens difficult to list within a money market. This represents assets like LSDs (rpETH, stETH, etc), timelocked LPs (Chicken Bonds) and, veTokens.
We know what happens when things go right – Aave listing stETH and the corresponding looped leveraged resulted in billions in TVL for both Aave and Lido. We also knows what goes wrong with these derivative tokens. Manipulable oracles, in addition to low underlying dex liquidity have meant that it can be difficult to use these derivatives in a money market context.
This is why we’re taking a different approach to lending for these assets, a physically settled P2P lending market for these assets.
We built it out and got interest from DAOs that wanted to get cashflows from their holdings, like Alchemix, Redacted Cartel, and M11 Credit as well as made it to the final round of the AllianceDAO and Geometry accelerators. However, I then got cold feet from doing this startup for two reasons: firstly, I wasn’t sure if this is the problem I wanted to work on for the next 3-5 years and secondly, I wasn’t sure if I was good enough to found a startup. Because of this, I decided to stop working on Stardust and stepped back from crypto altogether.
Website: &lt;a href=&quot;https://stard.st/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://stard.st/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kinesis Labs I wanted to get some experience running a DeFi project, so ran this saddle finance fork on Evmos and added some features like dynamic fees! Got to ~600k tvl and learned a bunch about how DeFi really works behind the scenes. Made enough mon
ey from this and Risk Harbor to give myself some time to sit and think about what to do next which is really helpful.&lt;/p&gt;
&lt;p&gt;Website: &lt;a href=&quot;https://kinesislabs.co/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://kinesislabs.co/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Evmos Intern I wanted to help out some of my friends(ex-blockchain at berkeley) with Evmos, and created the Evmos Intern account to grow DeFi on Evmos. I also wanted to see if growing a project via constructive and positive tweets would be different from throwing fud and technical explanations on twitter. Here are some sample tweets:
&lt;a href=&quot;https://twitter.com/evmosintern/status/1548737661950521344&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://twitter.com/evmosintern/status/1548737661950521344&lt;/a&gt;
&lt;a href=&quot;https://twitter.com/evmosintern/status/1548737976561045504&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://twitter.com/evmosintern/status/1548737976561045504&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;ParadigmEng420 I wanted to grow an anon twitter account, just to see if I could. I got the perfect opportunity when the Nomad bridge got hacked. I was pretty early to the hack, as only ~40 minutes had gone by since the initial hack transactions. I then took a few hours to look into how the hack worked and published a tweet thread explaining the technicals, frontrunning samczsun’s inevitable thread. I went from 0-1k followers from that thread.
&lt;a href=&quot;https://twitter.com/ParadigmEng420/status/1554249610574450688&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://twitter.com/ParadigmEng420/status/1554249610574450688&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The second big thread was the aptos fud thread. Since aptos mainnet had just been announced and most of crypto twitter hated aptos, it was the perfect time to publish a hit piece to gain traction off that sentiment. I threw together some lies and half truths about the aptos tps and the token distribution and went from 1k-5k followers off that tweet.
&lt;a href=&quot;https://twitter.com/ParadigmEng420/status/1582121408548651009&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://twitter.com/ParadigmEng420/status/1582121408548651009&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Wormhole explorer Wormhole has a rate limit, where only a certain amount of value can be sent cross-chain in any given day. This was a CalHacks project that tracked past on-chain transactions on Wormhole, but also off-chain transactions in their gossip network to make sure any transactions sent wouldn’t be rejected by their guardians. I worked on this with 3 other members of blockchain at berkeley.&lt;/p&gt;
&lt;p&gt;Jump Crypto liked the project enough such that they ended up paying blockchain at berkeley to work on two continuations of this project for 15k each which was pretty cool.&lt;/p&gt;
&lt;p&gt;Muteswap I worked on this project with 0xfoobar and his team, mostly along the lines of research and business development. At the end of the day, the legal risk of this project was simply unacceptable to us since it is basically a glorified tornado cash + uniswap and tornado cash had just gotten sanctioned so we agreed to shut it down.
&lt;a href=&quot;https://twitter.com/muteswap&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://twitter.com/muteswap&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Risk Harbor This was my first serious foray into crypto. I mostly did contracts and integrations for them, growing from 0 to 200 million TVL, writing wrappers that would programmatically detect whether a given DeFi protocol had been hacked and automatically pay out insurance if there had been a hack.&lt;/p&gt;
&lt;p&gt;Klade This was my first crypto project, we built a way for bitcoin miners to hedge increases in hash rate. Unfortunately, it went nowhere, mostly because a) the mechanism was not capital efficient and b) we didn’t understand business development(or anything for that matter).&lt;/p&gt;
&lt;p&gt;Before Crypto
First coding experience was writing games with tynker
I didn’t get comfortable enough with building hackathon level projects till the 11th grade, where I started doing a lot of “NLP” projects for hackathons, which basically meant using the Amazon Alexa SDK(back when amazon docs were super ugly) and feeding it a series of hardcoded Q&amp;#x26;A logic or using basic word vectorization tools like GloVe and word2vec.&lt;/p&gt;
&lt;p&gt;Non Crypto
Worked on Coinbase NFTs
Worked at the NSA
Did research using NLP(GloVe) at the haas neuroeconomics lab&lt;/p&gt;
&lt;p&gt;Shorter Crypto Experiences
Governance at Blockchain at Berkeley: Delegate on Aave, Compound, Dydx, Optimism, Uniswap Ex: Maker, FEI, Soon: Euler&lt;/p&gt;
&lt;p&gt;Basically, we vote yes on everything until something big comes up, then we wait for the big boys like jump and a16z to call us and tell us how to vote.&lt;/p&gt;
&lt;p&gt;Quickfire
Favorite Project:
Favorite Github Repo:
Most bullish on:
Least bullish on:&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Ideas on Tech]]></title><description><![CDATA[List of ideas and links related to tech]]></description><link>https://albertsu.netlify.app//posts/misc/tech-ideas</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/misc/tech-ideas</guid><pubDate>Mon, 20 Nov 2023 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;short-form&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#short-form&quot; aria-label=&quot;short form permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Short form&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;If you ever need to send someone instructions on how to do something or are showing them something they will need to remember how to do. Instead of worrying notes, windows +r to open run command and type in psr.exe. This opens a utility you can then record all your steps. It creates a nice step by step document detailing everything you click on and captures screenshots.&lt;/li&gt;
&lt;li&gt;Join Facebook Group to get names of people that go to a certain university
Use chrome extension that allows you to get people’s email given organization, first and last name
Make a mass email list in hours.&lt;/li&gt;
&lt;li&gt;Can you hash people’s faces into something unique and robust?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;university-related&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#university-related&quot; aria-label=&quot;university related permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;University Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;CS61c material: &lt;a href=&quot;https://jyunicorn.github.io/teaching.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://jyunicorn.github.io/teaching.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;List of Remote companies hiring: &lt;a href=&quot;https://github.com/yanirs/established-remote&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://github.com/yanirs/established-remote&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;NSF REUs: &lt;a href=&quot;https://www.nsf.gov/crssprgm/reu/list_result.jsp?unitid=5049&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.nsf.gov/crssprgm/reu/list_result.jsp?unitid=5049&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Top University Admissions officer: &lt;a href=&quot;https://www.removeddit.com/r/ApplyingToCollege/comments/9f8zl3/_/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.removeddit.com/r/ApplyingToCollege/comments/9f8zl3/_/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;16b notes: &lt;a href=&quot;https://github.com/rahularya50/EE16B-Notes&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://github.com/rahularya50/EE16B-Notes&lt;/a&gt;, &lt;a href=&quot;https://github.com/saahilchadha1/EE16B-Notes/tree/master/pdfs&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://github.com/saahilchadha1/EE16B-Notes/tree/master/pdfs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;defi&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#defi&quot; aria-label=&quot;defi permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;DeFi&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Defi Accelerator: &lt;a href=&quot;https://www.defialliance.co/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.defialliance.co/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Defi safety: &lt;a href=&quot;https://docs.defisafety.com/misc-and-in-work/pancakeswap-process-quality-review-v2#author-details&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://docs.defisafety.com/misc-and-in-work/pancakeswap-process-quality-review-v2#author-details&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Defi score: &lt;a href=&quot;https://defiscore.io/overview&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://defiscore.io/overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Intro to bitcoin: &lt;a href=&quot;https://michaelnielsen.org/ddi/how-the-bitcoin-protocol-actually-works/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://michaelnielsen.org/ddi/how-the-bitcoin-protocol-actually-works/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;internships&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#internships&quot; aria-label=&quot;internships permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Internships&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Leetcode prep: &lt;a href=&quot;https://github.com/jwasham/coding-interview-university&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://github.com/jwasham/coding-interview-university&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Resume Rules: &lt;a href=&quot;https://www.nicksingh.com/posts/36-resume-rules-for-software-engineers&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.nicksingh.com/posts/36-resume-rules-for-software-engineers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;School of SRE: &lt;a href=&quot;https://linkedin.github.io/school-of-sre/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://linkedin.github.io/school-of-sre/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Blind top 75: &lt;a href=&quot;https://www.teamblind.com/post/New-Year-Gift---Curated-List-of-Top-75-LeetCode-Questions-to-Save-Your-Time-OaM1orEU&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.teamblind.com/post/New-Year-Gift---Curated-List-of-Top-75-LeetCode-Questions-to-Save-Your-Time-OaM1orEU&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;System Design Framework: &lt;a href=&quot;https://www.teamblind.com/post/Willing-to-help-for-system-design-xQQ5u63y&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.teamblind.com/post/Willing-to-help-for-system-design-xQQ5u63y&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;learning-tech-stuff&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#learning-tech-stuff&quot; aria-label=&quot;learning tech stuff permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Learning Tech Stuff&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Web dev tutorial: &lt;a href=&quot;https://www.theodinproject.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.theodinproject.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SQL tutorial: &lt;a href=&quot;https://mystery.knightlab.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://mystery.knightlab.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;No code websites: &lt;a href=&quot;https://www.nocode.tech/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.nocode.tech/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#misc&quot; aria-label=&quot;misc permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Places to shill at: &lt;a href=&quot;https://www.notion.so/logology/Where-to-post-your-project-4b6b9c20d7d7462f871e7e71b6449f62&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.notion.so/logology/Where-to-post-your-project-4b6b9c20d7d7462f871e7e71b6449f62&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Polygraph stuff: &lt;a href=&quot;https://antipolygraph.org/documents/dodpi-interrogation.pdf&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://antipolygraph.org/documents/dodpi-interrogation.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Notebook fan control: &lt;a href=&quot;https://github.com/hirschmann/nbfc/wiki/FAQ&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://github.com/hirschmann/nbfc/wiki/FAQ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Bootstrap themes: &lt;a href=&quot;https://www.creative-tim.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.creative-tim.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Hawk and serpent(Investing read): &lt;a href=&quot;https://artemiscm.docsend.com/view/taygkbn&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://artemiscm.docsend.com/view/taygkbn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Networking with people: &lt;a href=&quot;https://bryanwang.substack.com/p/a-guide-to-authentic-networking&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://bryanwang.substack.com/p/a-guide-to-authentic-networking&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;long-form&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#long-form&quot; aria-label=&quot;long form permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Long form&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Toxicity in Computer Science:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A lot of people get into software because the computer understands them. The computer doesn’t make faces that you don’t understand or behave in ways that are unpredictable. So you spend more time with the computer than people. The software doesn’t make fun of you or talk about you behind your back.&lt;/li&gt;
&lt;li&gt;Then as you grow older and enter college you meet hundreds of other people just like you. And now all of the social deficiencies that you had in high school are celebrated as eccentricities. So you are pushed even further away from people and into the world of software. And in this world the only thing that matters is your grade on the assignment. Nobody grades you how well you are liked personally by your peers.&lt;/li&gt;
&lt;li&gt;Then you enter the workforce and you are a rockstar. You’re making more money out of the gate than most of your high school friends who majored in communication or business. And the more you learn, the more money you make. You buy a new car, you get a better apartment. And you must be smart because you look back at all of the people who made fun of you in high school and they are working at an insurance company for $16 an hour and you think : “I always knew I was smarter than them.”&lt;/li&gt;
&lt;li&gt;So when someone asks a question on Reddit or Stackoverflow you jump on them because why can’t they see it? It’s obvious. Maybe they shouldn’t be in this profession because they can’t compete with how very smart you are.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;cool-projects-from-eth-hackathons&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cool-projects-from-eth-hackathons&quot; aria-label=&quot;cool projects from eth hackathons permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cool projects from eth hackathons&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://ethglobal.com/showcase/safenode-shtqy&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/safenode-shtqy&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/2inch-wxtu0&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/2inch-wxtu0&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/freedombridge-fcab4&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/freedombridge-fcab4&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/cross-margin-engine-for-derivatives-zgy04&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/cross-margin-engine-for-derivatives-zgy04&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/sdao-sorition-based-dao-gjcbr&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/sdao-sorition-based-dao-gjcbr&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/leverage-yield-yf3a4&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/leverage-yield-yf3a4&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/sheeth-the-wallet-condom-pvq8n&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/sheeth-the-wallet-condom-pvq8n&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/nested-amm-uwe1a&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/nested-amm-uwe1a&lt;/a&gt;
&lt;a href=&quot;https://ethglobal.com/showcase/decentra-date-j6u9t&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://ethglobal.com/showcase/decentra-date-j6u9t&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Dynamic Fees Postmortem]]></title><description><![CDATA[A postmortem of the security exploit in the Kinesis Contracts.]]></description><link>https://albertsu.netlify.app//posts/kinesis-labs/dynamic-fees-postmortem</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/kinesis-labs/dynamic-fees-postmortem</guid><pubDate>Fri, 20 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h1 id=&quot;kinesis-dynamic-fees-postmortem&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#kinesis-dynamic-fees-postmortem&quot; aria-label=&quot;kinesis dynamic fees postmortem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Kinesis Dynamic Fees Postmortem&lt;/h1&gt;
&lt;p&gt;Contact Information&lt;/p&gt;
&lt;p&gt;Telegram(Preferred): @kinesislabs&lt;/p&gt;
&lt;p&gt;Email: team@kinesislabs.co&lt;/p&gt;
&lt;p&gt;Discord: Dr.Kinesis#0157&lt;/p&gt;
&lt;h1 id=&quot;key-points&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#key-points&quot; aria-label=&quot;key points permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Key Points&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;All user funds are safe&lt;/li&gt;
&lt;li&gt;The issue here is incorrect arthimetic leading to safemath reverting when attemping to swap tokens, meaning swaps are disabled. However, users can still unstake and withdraw from the pools.&lt;/li&gt;
&lt;li&gt;The plan is to set &lt;code class=&quot;language-text&quot;&gt;rewardsPerSecond&lt;/code&gt; to 0 on the three current Simple Rewarders, send the rest of the staking rewards to the new SimpleRewarders, and ask users to migrate their funds to the new SimpleRewarders&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-issue&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-issue&quot; aria-label=&quot;the issue permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Issue&lt;/h3&gt;
&lt;p&gt;We initially got a report from multiple users in discord that they were having trouble swapping tokens in the new DAI/USDC/USDT pools. We initially chalked these up to RPC issues, which are not abnormal with the current Evmos infrastructure. However, when we got the following report from GV of Swiss Staking, we knew something was probably wrong as a power user like GV would know to change the RPCs and to try the transaction again after waiting a few minutes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./../../../public/static/images/kinesis/gv_swiss_staking.png&quot; alt=&quot;GV&amp;#x27;s message&quot;&gt;&lt;/p&gt;
&lt;p&gt;We then tested the exact swap ourselves, axlDAI for ibc G-DAI and got the following error.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./../../../public/static/images/kinesis/swap-error-message.png&quot; alt=&quot;Swap Error Message&quot;&gt;&lt;/p&gt;
&lt;p&gt;The error is &lt;code class=&quot;language-text&quot;&gt;execution reverted: SafeMath: division by zero&lt;/code&gt;. This was a very bad sign and we immediately knew something went very badly wrong with the contracts - this error could no longer be from Evmos infrastructure or our frontend.&lt;/p&gt;
&lt;p&gt;After triaging this a bit further, we found the exact line in the frontend that made this call to the &lt;code class=&quot;language-text&quot;&gt;swap()&lt;/code&gt; function and thus we knew the issue was in the &lt;code class=&quot;language-text&quot;&gt;swap()&lt;/code&gt; function of the contracts.&lt;/p&gt;
&lt;p&gt;The swap function is very simple, just two lines:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;    function swap(
        uint8 tokenIndexFrom,
        uint8 tokenIndexTo,
        uint256 dx,
        uint256 minDy,
        uint256 deadline
    )
        external
        payable
        virtual
        nonReentrant
        whenNotPaused
        deadlineCheck(deadline)
        returns (uint256)
    \{
        updateSwapFee(minDy);
        return swapStorage.swap(tokenIndexFrom, tokenIndexTo, dx, minDy);
    \}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There were only three functions that could have held this error, the &lt;code class=&quot;language-text&quot;&gt;deadlineCheck()&lt;/code&gt; modifier, the &lt;code class=&quot;language-text&quot;&gt;updateSwapFee()&lt;/code&gt; function, or the &lt;code class=&quot;language-text&quot;&gt;swapStorage.swap()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;deadlineCheck()&lt;/code&gt; does not have a SafeMath div call, meaning the error could not have been there. Additionally, the SafeMath divs in &lt;code class=&quot;language-text&quot;&gt;swapStorage.swap()&lt;/code&gt; both use constants, meaning it could not be those functions either.&lt;/p&gt;
&lt;p&gt;This narrows down the scope of the issue to the &lt;code class=&quot;language-text&quot;&gt;updateSwapFee()&lt;/code&gt; function. For full disclosure, this is a newly added function, which dynamically changes the swap fee based on the volume swapped in the last hour. There is one SafeMath div in the function.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;uint256 newSwapFee =
(feeFactor.mul(hourlyVolume))
.div(averageVolume).add(baseFee);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Since the error was &lt;code class=&quot;language-text&quot;&gt;execution reverted: SafeMath: division by zero&lt;/code&gt;, we know that averageVolume is zero, making the entire &lt;code class=&quot;language-text&quot;&gt;swap()&lt;/code&gt; function revert.&lt;/p&gt;
&lt;p&gt;Average Volume is set in &lt;a href=&quot;https://github.com/kinesis-labs/contract/blob/69c3449b1026bc217f12f7ac5f1f7ee14656ec0a/contracts/Swap.sol#L527&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Line 527&lt;/a&gt; and we can quickly see the error.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;averageVolume = averageVolume
.add(averageVolume.sub(recentVolume[recentVolumePointer].volume))
.mul((10 minutes / (block.timestamp.sub(creationTimestamp))));&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;10 minutes after the contract is created, &lt;code class=&quot;language-text&quot;&gt;block.timestamp.sub(creationTimestamp)&lt;/code&gt; will be greater than &lt;code class=&quot;language-text&quot;&gt;10 minutes&lt;/code&gt;. In solidity, there are no decimals, so &lt;code class=&quot;language-text&quot;&gt;1/2&lt;/code&gt; will round to zero. Thus, &lt;code class=&quot;language-text&quot;&gt;(10 minutes/block.timestamp.sub(creationTimestamp))&lt;/code&gt; will round to zero after the first 10 minutes, meaning that Average Volume will always be set to zero, and thus the &lt;code class=&quot;language-text&quot;&gt;swap()&lt;/code&gt; function will always revert.&lt;/p&gt;
&lt;h2 id=&quot;triaging-the-issue&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#triaging-the-issue&quot; aria-label=&quot;triaging the issue permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Triaging the Issue&lt;/h2&gt;
&lt;p&gt;The first thing we tested was withdrawing liquidity as we want to be 100% sure that user funds were not at risk. To this effect, we tested Deposit, Withdraw, Stake All, and Unstake All to ensure there are no issues with any of these functionality. Luckily, there were no issues here and USER FUNDS ARE SAFE.&lt;/p&gt;
&lt;p&gt;Thus, there are a few issues to keep in mind. We want Kinesis to be a useful application on Evmos instead of a place to stake stablecoins to receive Evmos. Thus, we would need to either upgrade the contract or to deploy new contracts. Unfortunately, we do not have upgrade functionality to violate the core principles of decentralization and immutability.&lt;/p&gt;
&lt;p&gt;We then decided the best way forward would be to redeploy the contracts and send the rest of the rewards(87,343.52 wEVMOS) to the new simple rewarders.&lt;/p&gt;
&lt;h2 id=&quot;next-steps&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#next-steps&quot; aria-label=&quot;next steps permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Next Steps&lt;/h2&gt;
&lt;h3 id=&quot;redeploying-contracts&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#redeploying-contracts&quot; aria-label=&quot;redeploying contracts permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Redeploying Contracts&lt;/h3&gt;
&lt;p&gt;Contracts have already been redeployed to these addresses:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;USDCPool: 0x35bF604084FBE407996c394D3558E58c90281000
USDCPoolLPToken: 0xfD2fd675176a8Ed1CF643886ee557929FDEcBBfD
USDTPool: 0x89E9703309DA4aC51C739D7d674F91489830310E
USDTPoolLPToken: 0x78549EF94dB08E8bf2e528F0aE97F186Fc51185E
DAIPool: 0x155377C4f5489026cD8340fF350ae6aa082FBE69
DAIPoolLPToken: 0x9607FFD92DC6846F913129d8351a848240BEC4E9
MiniChefV2: 0x82a4A94eC86f03bf1a5979B41e2Ae8478C93f9C3
SimpleRewarder_usdc: 0x5Ff26712e2Ec975d7F25a31Ba7c9FbA395655076
SimpleRewarder_usdt: 0xDc85D4f941B8adc7cF223C9AFd5305c2684D7090
SimpleRewarder_dai: 0x0BCC8b2E95e0e59a23fc6D8DD653636047cf3C3f&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The frontend has also been redeployed here with the new pools and the old pools.
&lt;a href=&quot;https://frontend-git-a-featpostmortem-kinesislabs.vercel.app/#/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://frontend-git-a-featpostmortem-kinesislabs.vercel.app/#/&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;sending-rewards&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sending-rewards&quot; aria-label=&quot;sending rewards permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sending Rewards&lt;/h3&gt;
&lt;p&gt;Afterwards, we need sent the rest of the wEVMOS liquidity mining rewards to the new Simple Rewarders. This process would be the exact same as what LPX already has done in the past.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LPX, can you initiate the transactions for this when we have agreed to a path forward?&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;public-announcement-to-migrate-funds&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#public-announcement-to-migrate-funds&quot; aria-label=&quot;public announcement to migrate funds permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Public Announcement to Migrate Funds&lt;/h3&gt;
&lt;p&gt;We will need to make a public announcement for users to migrate funds from the old pools which will be depreceated to the new pools. There are two options here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We can admit we messed up and explain the full scope of the issue&lt;/li&gt;
&lt;li&gt;We can hide this as a routine upgrade to activate dynamic fees.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We are leaning towards the former reason, however, if others in the Evmos ecosystem wish to use the latter reasoning to keep confidence in the ecosystem, that is understandable as well.&lt;/p&gt;
&lt;h3 id=&quot;set-rewards-per-second-to-zero&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#set-rewards-per-second-to-zero&quot; aria-label=&quot;set rewards per second to zero permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Set Rewards Per Second to Zero&lt;/h3&gt;
&lt;p&gt;Finally, we would set rewards per second on the current SimpleRewarder Contracts. This is to ensure everyone can unstake their LP tokens from Minichef such that they can withdraw their LP tokens, as if there are not enough LP tokens on Minichef, users will no longer be able to unstake their LP tokens.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LPX, can you initiate these three transactions? You would need to call&lt;/li&gt;
&lt;li&gt;-&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;function setRewardPerSecond(uint256 _rewardPerSecond) public onlyOwner \{
        rewardPerSecond = _rewardPerSecond;
        emit LogRewardPerSecond(_rewardPerSecond);
    \}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;in SimpleRewarder.sol with &lt;code class=&quot;language-text&quot;&gt;_rewardPerSecond&lt;/code&gt; set to 0.&lt;/p&gt;
&lt;h3 id=&quot;todos-on-kinesis-end&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#todos-on-kinesis-end&quot; aria-label=&quot;todos on kinesis end permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;TODOs on Kinesis’ End&lt;/h3&gt;
&lt;p&gt;Update Minichef to the new minichef contract address on the frontend when rewards are live on the new contracts&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Artificial Growth - Giving out 100k in 60 days to grow faster]]></title><description><![CDATA[A postmortem of the Kinesis Labs Liquidity Mining Governance Proposals.]]></description><link>https://albertsu.netlify.app//posts/kinesis-labs/governance</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/kinesis-labs/governance</guid><pubDate>Fri, 20 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The easiest way to grow your defi protocol is to start liquidity mining. Normally, projects will distribute their token
&lt;a href=&quot;https://commonwealth.im/evmos/discussion/4752-bootstrap-liquidity-on-evmos-dapps&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://commonwealth.im/evmos/discussion/4752-bootstrap-liquidity-on-evmos-dapps&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://commonwealth.im/evmos/discussion/6844-temperature-check-start-liquidity-mining-campaign-for-gravity-celer-and-axelar-assets&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://commonwealth.im/evmos/discussion/6844-temperature-check-start-liquidity-mining-campaign-for-gravity-celer-and-axelar-assets&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://commonwealth.im/evmos/discussion/7017-passed-proposal-for-axelar-network-celer-network-and-gravity-bridge-liquidity-mining&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://commonwealth.im/evmos/discussion/7017-passed-proposal-for-axelar-network-celer-network-and-gravity-bridge-liquidity-mining&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;appendix&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#appendix&quot; aria-label=&quot;appendix permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Appendix&lt;/h2&gt;
&lt;p&gt;Temperature check - Start Liquidity Mining Campaign for Gravity, Celer, and Axelar assets&lt;/p&gt;
&lt;p&gt;Hi Evmos Community!&lt;/p&gt;
&lt;p&gt;We are planning to make a proposal next week: Liquidity mining campaigns for stablecoins from Celer Network, Gravity Bridge, and Axelar Network.&lt;/p&gt;
&lt;p&gt;The goal of this proposal is to bring stablecoin liquidity back to Evmos. In the past, Kinesis Labs has reached over 255k USD worth of stablecoins in TVL without any incentives, with over 11,000 transactions and 400 unique liquidity providers. All of this was organic liquidity from the Evmos community, there were no funds or deals done to bootstrap this liquidity.&lt;/p&gt;
&lt;p&gt;However, with the recent nomad hack, both Kinesis and Evmos need a way to bootstrap liquidity to jump start the Evmos DeFi ecosystem. We propose the following plan to bring stablecoin liquidity back to Evmos:&lt;/p&gt;
&lt;p&gt;33k Evmos tokens to be distributed to the Axelar Network Pool over 6 months as soon as they finish their deployment to Evmos mainnet. Please note that the assets in this pool are to be decided as we are still unsure what assets will get adoption on Evmos, but the pool will likely consist of blue chip stablecoins.&lt;/p&gt;
&lt;p&gt;33k Evmos tokens to be distributed to the Celer Network Pool over 6 months as soon as the proposal passes. Please note that the assets in this pool are to be decided as we are still unsure what assets will get adoption on Evmos, but the pool will likely consist of blue chip stablecoins.&lt;/p&gt;
&lt;p&gt;33k Evmos tokens to be distributed to the Gravity Bridge Pool over 6 months as soon as this proposal passes. Please note that the assets in this pool are to be decided as we are still unsure what assets will get adoption on Evmos, but the pool will likely consist of blue chip stablecoins.&lt;/p&gt;
&lt;p&gt;We are requesting a total of 99k Evmos for this proposal to be linearly distributed over 6 months.&lt;/p&gt;
&lt;p&gt;All of these funds will be distributed to liquidity providers on Kinesis through the minichef contract, no funds will ever reach an EOA or multisig - these funds are not for the Kinesis Team nor the Axelar, Celer, or Gravity teams. Additionally, the only fee on Kinesis is the 0.04% swap fee which goes entirely to LPs, and Kinesis does not currently have a token or any other value extraction mechanism. We are building this project as members of the Evmos ecosystem as a public good.&lt;/p&gt;
&lt;p&gt;The multisig that controls these funds will be a 4 out of 6 consisting of:
Nic Z, Co-Founder of Tharsis (Evmos Core Team)
Akash Khosla, Co-Founder of Tharsis (Evmos Core Team)
Liam DiGregorio, Head of Business Development at Tharsis (Evmos Core Team)
Mo Dong, Co-Founder of Celer Network
Deborah Simpier, Co-Founder and CEO of Althea (Gravity Bridge)
Georgios Vlachos, Co-Founder of Axelar&lt;/p&gt;
&lt;p&gt;The reasoning behind these members is that these would be the key stakeholders for this proposal as they are members of Tharsis, the team building Evmos as well as one representative from each bridge that will be launching. There will be&lt;/p&gt;
&lt;p&gt;Additionally, Celer will match this with a minimum of 1m in Celer stablecoin liquidity, which will be deposited into the Celer stablecoin pools.&lt;/p&gt;
&lt;p&gt;We’ve been working closely with the Axelar Network, Celer Network, Gravity Bridge teams on this initiative. If there’s any questions, the Kinesis + Axelar + Celer + Gravity bridge teams will be happy to answer down below.&lt;/p&gt;
&lt;p&gt;Background on Axelar Network
Summary:
Axelar network is built from the ground up using Cosmos SDK to interoperate between Cosmos chains, EVM chains, Bitcoin, and other PoS and PoW chains. Satellite is the cross-chain asset transfer app built on top of the network and has amassed over $37m TVL and 100k cross-chain transactions since launching in February. It has also recently become the official canonical bridge for Osmosis and plans to further expand its reach into the Cosmos and EVM ecosystem.&lt;/p&gt;
&lt;p&gt;Satellite currently supports Avalanche, Polygon, Terra, Osmosis, Moonbeam, Fantom, Ethereum and Cosmos Hub with plans to support all major EVM chains over the next couple months.&lt;/p&gt;
&lt;p&gt;Satellite connects all Cosmos chains via IBC and its GCP protocol with multiple ecosystems.
It’s built on top of Axelar’s “decentralized overlay network” that connects different blockchain stacks. Axelar serves as the translation layer that allows Cosmos assets to flow freely to all Axelar-interconnected networks and back. It is permissionless, meaning that anyone can join, submit transactions, relay, and validate.&lt;/p&gt;
&lt;p&gt;Axelar has been audited by Ackeeblockchain, Cure53, NCC, Oak Security, Commonprefix labs and independent researchers and is also dedicating at least 5% of AXL supply to an insurance fund/program that will help recuperate any stolen funds to ensure the safety of its users.&lt;/p&gt;
&lt;p&gt;Security:&lt;/p&gt;
&lt;p&gt;Axelar believes that bridging solutions should be at least as secure as the chains being bridged. Axelar’s solution is having a Cosmos chain, one with a similar validator set to other chains. Additionally, they are heavily invested in securing their smart contracts and in applying cutting-edge cryptography.&lt;/p&gt;
&lt;p&gt;The Axelar network isolates functionalities in modules at the Cosmos SDK level, e.g., one module for bitcoin, another for EVM chains, another for IBC transfers, etc.&lt;/p&gt;
&lt;p&gt;Each module handles the respective transactions from source and destination chains and are isolated from each other and messages can only be passed through a router module. If there is an issue with one or all chains, a special transfer command that can be supplied by the governance multisig can pause the router module.&lt;/p&gt;
&lt;p&gt;There is also minimal reliance on smart contracts and are only used for key-rotations and mint/burn operations.&lt;/p&gt;
&lt;p&gt;The mint/burn contracts can also be freezed in case of a compromise and have a rate-limit functionality that allows to minimize how much funds can be stolen in case of an attack. This is not enabled on the mainnet at the moment, but can be considered along with other “access control” policies to minimize attacks.&lt;/p&gt;
&lt;p&gt;There will also be an insurance fund/program of at least 5% of the AXL supply to compensate users in case of stolen funds. Axelar has also been audited by Ackeeblockchain, Cure53, NCC, Oak Security, Commonprefix labs and independent researchers and gone through a dozen audits.&lt;/p&gt;
&lt;p&gt;Costs:&lt;/p&gt;
&lt;p&gt;Axelar currently has a set fee on each transfer that covers gas costs on source + destination chain. Axelar foundation subsidizes any increase in the destination gas cost if need be and is also considering subsiding fees further from its treasury.&lt;/p&gt;
&lt;p&gt;Transactions are also batched, reducing the gas costs for the users significantly. Axelar also has active implementation of threshold signatures that can be used to replace individual validator signatures and further save gas costs. While not currently deployed in EVM contracts, this is just one of the many code-level gas optimizations that Axelar will ship in the future.&lt;/p&gt;
&lt;p&gt;Users only pay the fee in the asset they transfer on the source chain, and all other fees (relaying / intermediary / destination chains) are covered by services around the network.&lt;/p&gt;
&lt;p&gt;App:
&lt;a href=&quot;https://satellite.axelar.network/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://satellite.axelar.network/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Background on Celer Network
Summary:
Celer Network is a multi-chain operating system built with Cosmos SDK. Celer released the world’s first EVM-supported inter-chain message SDK. and has a track record of no hacks for any product since Celer originated in 2018.&lt;/p&gt;
&lt;p&gt;Celer cBridge is a token bridge application built on top of Celer that supports 45 different tokens across 21 different blockchains and layer-2 rollups. cBridge has &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;400&lt;/mn&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;mi&gt;V&lt;/mi&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;400M TVL and has processed more than&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8888799999999999em;vertical-align:-0.19444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;MT&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.22222em;&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;an&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;ha&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;rocesse&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;ore&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;han&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;4B of cross-chain volume for 105K unique users with a daily volume of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;50&lt;/mn&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;50M-&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.76666em;vertical-align:-0.08333em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;−&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;60M across 21 different blockchains.&lt;/p&gt;
&lt;p&gt;cBridge comes with two security models that every user can choose between, the Cosmos-consensus security model and an optimistic-rollup-style delay buffer security model. The consensus model is security that of a validator-based bridge, while the optimistic rollup style also has a delay buffer to allow an independent watchtower service to double check the message.&lt;/p&gt;
&lt;p&gt;Users have single-click UX with fast confirmation of the bridge between source and destination chains and with 2,500-3,500 daily active users comfortable with using Celer Network.&lt;/p&gt;
&lt;p&gt;Security:&lt;/p&gt;
&lt;p&gt;Cosmos-consensus Security Model:
Celer SGN is running as a Cosmos chain with the same level of liveness assumption which is very high like other Cosmos chains. Celer provides an L1-blockchain level security like Cosmos or Polygon as a Proof-of-Stake chain built on Tendermint with CELR as the staking asset. If a validator acts maliciously, their CELR will be slashed.&lt;/p&gt;
&lt;p&gt;Optimistic-rollup-style delay buffer Security Model:
Inter-chain dApps can maintain full security with an optimistic-style delay buffer. Instead of instantly processing a message through the consensus model, one can inject a mandatory delay buffer and run an independent watchtower service to double-validate the message on the source chain. If the watchtower service detects any inconsistency, it can prevent the message from being processed before the delay expires.&lt;/p&gt;
&lt;p&gt;For transactions larger than a certain amount, two-transactions are needed to make the bridge happen: a “commit” transaction that will trigger the time buffer and then after the time buffer, a “confirm” transaction. The watchtower system also monitors the bridge for small transactions as well to detect and prevent any unexpected smart contract bugs. There is also rate-limiting for token bridging as the last-resort to worst-case scenario.&lt;/p&gt;
&lt;p&gt;In addition, Celer cBridge smart contract has been heavily audited and also has a $2M ImmuneFi bug bounty. Celer Network also has a track record since 2018 of no hacking event happening for any product they have built.&lt;/p&gt;
&lt;p&gt;Costs:
cBridge charges the gas fee on the destination chain to cover the operation costs of validators. The fee is not related to the size of the transaction, unlike many other bridging solutions.&lt;/p&gt;
&lt;p&gt;Celer also has no plans to change the fee structure and remains committed to supporting inter-chain apps where IBC is not available. Unlike other bridges that plan on changing to percentage-based fees later, Celer will only charge a flat fee based on the size of the message passed to provide revenue for validators.&lt;/p&gt;
&lt;p&gt;There are also no platform fees charged by the Celer Network for token asset bridging.&lt;/p&gt;
&lt;p&gt;App:
&lt;a href=&quot;https://cbridge.celer.network/#/transfer&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://cbridge.celer.network/#/transfer&lt;/a&gt;
Background on Gravity Bridge&lt;/p&gt;
&lt;p&gt;Summary:
The Gravity Bridge blockchain is the trustless, neutral bridge between Ethereum and the Cosmos ecosystem. The principal focus of the Gravity community is on providing the most effective and secure bridge possible, instead of a DeFi application on the local chain.&lt;/p&gt;
&lt;p&gt;Gravity Bridge protocol focuses on creating a simple bridge design that focuses on providing better security by eliminating design complexity and using non-upgradeable contracts which have been audited by Certick, Least Authority and Cod4rena.&lt;/p&gt;
&lt;p&gt;The Gravity Bridge protocol provides strong censorship resistance guarantees and the bridge will remain live as long as the chain remains live, i.e. with more than 2/3 of validators active.&lt;/p&gt;
&lt;p&gt;Currently supports Ethereum and has plans to support additional EVM chains before the end of 2022.&lt;/p&gt;
&lt;p&gt;While there is not currently a set-aside for an insurance fund, one could easily be set aside from the community pool which contains 50% of $GRAV token distribution which could also contain a collection of assets.&lt;/p&gt;
&lt;p&gt;Security:&lt;/p&gt;
&lt;p&gt;Gravity Bridge is trustless, decentralized and highly efficient and offers the closest approximation of IBC security possible. It is highly decentralized with all funds directly controlled by validators with slashing to deter validators from acting in bad faith.&lt;/p&gt;
&lt;p&gt;The Gravity Bridge design means that the only way to attack the bridge is to go through the validators themselves. This results in a trustless bridge that costs less to operate than a custodial one. It is not possible for a validator to avoid signing a specific transaction or for a relayer to avoid relaying it. Anyone can submit evidence of a signature over a non-protocol message to slash a validator which makes it extremely difficult for validators to steal funds.&lt;/p&gt;
&lt;p&gt;The Gravity Bridge, like all bridges, has two components. A Solidity contract on Ethereum and a CosmosSDK module on the Gravity Bridge blockchain.&lt;/p&gt;
&lt;p&gt;The solidity contract that holds funds on Ethereum is merely 580 lines of code, which makes it compact and easy to review. It has been audited by three independent teams (Certik, Least Authority, and Code4rena), and it is not upgradable. It requires no trusted parties and can be temporarily paused by governance vote in case of a possible security breach. As a final layer of protection the Gravity Bridge blockchain performs a series of integrity checks that will halt the chain on any unexpected behavior.&lt;/p&gt;
&lt;p&gt;While there’s nothing set for an insurance fund at the moment, the $GRAV token holders can choose to use some funds from the large community pool to help recuperate stolen funds.&lt;/p&gt;
&lt;p&gt;Costs:&lt;/p&gt;
&lt;p&gt;Robust relaying reward systems combined with reduced gas costs creates extremely fast &amp;#x26; reliable transfers with a decentralized, self-funded, relayer community&lt;/p&gt;
&lt;p&gt;Gravity Bridge batches withdraw transactions. This works like a rollup on Ethereum. Executing many transactions in a single shared context is far more efficient than doing so individually. This process provides huge efficiency gains, up to 96% reduction in gas cost.&lt;/p&gt;
&lt;p&gt;Once bridge traffic has matured, tx fees could be enabled by the community to sustain the community pool. These tx fees are payable in a wide variety of tokens, not solely in GRAV. Other mechanisms, like a portion of the inflation, could be used to fund the community pool.&lt;/p&gt;
&lt;p&gt;App:
&lt;a href=&quot;https://spacestation.zone/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://spacestation.zone/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Background on Kinesis
About Kinesis:
Kinesis is a decentralized automated market maker (AMM) on the EVMOS blockchain, optimized for trading pegged value crypto assets with minimal slippage such as stablecoins. Through Kinesis, all traders can swap their desired stablecoins between EVM compatible blockchains and Cosmos chains.&lt;/p&gt;
&lt;p&gt;Kinesis enables efficient, swift, and low-slippage swaps for traders and high-yield for liquidity providers. We believe in collaboration with other Cosmos projects, in maximizing the interoperability of Kinesis, and in building out the stablecoin ecosystem for Cosmos.&lt;/p&gt;
&lt;p&gt;Kinesis has no governance token, no admin fees, and no value extraction mechanism. We are building this project as members of the Evmos ecosystem as a public good.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Crypto]]></title><description><![CDATA[Actually Useful Study Tips]]></description><link>https://albertsu.netlify.app//posts/reflections/crypto</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/reflections/crypto</guid><pubDate>Fri, 20 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h1 id=&quot;everything-im-still-bullish-on&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#everything-im-still-bullish-on&quot; aria-label=&quot;everything im still bullish on permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Everything I’m still bullish on&lt;/h1&gt;
&lt;h2 id=&quot;bullish-on-team-and-idea&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bullish-on-team-and-idea&quot; aria-label=&quot;bullish on team and idea permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bullish on Team and Idea&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Eigenlayer&lt;/strong&gt;: You’ve probably heard of Eigenlayer by now. For me, Eigenlayer is one a project that has the potential to grow so big that it becomes an existential threat to Ethereum, since if the supply of re-staked ETH approaches the total supply of staked ETH, weird incentives around the Ethereum Consensus mechanism could happen - or worse yet, there is an exploit in one of Eigenlayers’ contracts. The reason for Eigenlayer’s near guarenteed success is simple: anything that can be innovated on in the Ethereum ecosystem will be tested with Eigenlayer first. The main risks to Eigenlayer are also close to solved. Eigenlayer needs to grow fast enough to generate an ecosystem of applications that use restaked ETH, otherwise they risk someone forking their ecosystem and giving a bit less of their tokens to investors. k&lt;/p&gt;
&lt;p&gt;Additionally, the team is a powerhouse. Instead of being a collection of anons that met on the internet, Sreeram Kanaan brought his entire research lab from the University of Washington - Seattle, a top 10 CS research university. Having met a few of the team, here are some highlights: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Sreeram: Professor at UW, Postdoc at Stanford and UC Berkeley. He’s one of those rare people who has massive raw brainpower. I learned more about consensus mechanisms in 1 hour talking to this man than in the previous six months.&lt;/li&gt;
&lt;li&gt;Gautam: A paradigm fellow, a child genius who only eats frozen vegetables and hard boiled eggs for entire weeks since “life is too comfortable”&lt;/li&gt;
&lt;li&gt;CryptoBanker: Has found multiple exploits in live contracts as a whitehat&lt;/li&gt;
&lt;li&gt;Bowen, Shoubik, and the rest of the lab: PhDs at UW, nuff said.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Hot take: One year after Eigenlayer launches, it will have the highest TVL in all of Crypto.&lt;/p&gt;
&lt;h3 id=&quot;projects-to-be-built-on-top-of-eigenlayer&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#projects-to-be-built-on-top-of-eigenlayer&quot; aria-label=&quot;projects to be built on top of eigenlayer permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Projects to be built on top of Eigenlayer&lt;/h3&gt;
&lt;p&gt;Hyperscale Data Availability Layer: We can build a DA layer providing high DA rate and low cost by utilizing EigenLayer re-staking and some of the cutting edge ideas in data availability developed in the Ethereum community, including Danksharding.
Notes: The Eigenlayer team is already working on this as the first product, not much alpha to take from here unless you want to challenge them on their own turf.&lt;/p&gt;
&lt;p&gt;Decentralized Sequencers: Many rollups require decentralized sequencers for managing MEV and censorship-resistance at L2. These can be easily built on EigenLayer exploiting ETH stakers.
Notes: Not sure how this would work nor what a value a decentralized sequencer would bring&lt;/p&gt;
&lt;p&gt;Light-node bridges: It is easy to build light-node bridges to Ethereum using EigenLayer. For example, the rainbow bridge between Near and Ethereum is based on an optimistic pattern but it suffers from high-latency due to the high gas-cost of verification. It is possible for re-stakers to verify off-chain whether such inputs are correct, and if a strong cryptoeconomic quorum signs off on the bridge input, then the bridge input is considered accepted. If someone challenges, then the bridge input can be verified and the restakers can be slashed in the slow mode.
Notes: This is just an optimistic bridge with no privileged positions, it also speeds up existing bridges&lt;/p&gt;
&lt;p&gt;Fast-mode bridges for Rollups For ZK rollups, since the proof verification expense on Ethereum is still high, the rollup sequencers write to Ethereum somewhat infrequently, thus affecting composability and delaying strong confirmation guarantees. It is possible for a large amount of restaked quorum to participate in ZK proof verification offchain and certifying that proofs are correct on chain. These fast mode bridge claim if they turn out to be wrong can then trigger a slower slashing path. For optimistic rollups, eigenlayer can enable a much larger collateral pool to participate in certifying stateroots under risk of slashing.
Notes: This just speeds up bridging from rollup to eth mainnet. &lt;/p&gt;
&lt;p&gt;Oracles: There have been proposals for enshrining price feeds into Ethereum or using the UNI token quorum for providing price feeds. Such oracles can be potentially built via Eigenlayer if all we require is majority trust on Ethereum re-stakers, and it is an opt-in layer.
Notes: This is just a majority trust oracle. Simple, and not sure if someone would use this over coinbase. There would need to be major advancements needed here for this to be interesting, but sreeram and team say they have something interesting here.&lt;/p&gt;
&lt;p&gt;Opt-In Event-Driven Activation: Event-driven activations such as liquidations, collateral refilling are currently not available natively on Etheruem. While they can be built on a separate layer such as keepers, such keeper nodes which do not control blockspace cannot make strong guarantees on inclusion of event-driven actions. In EigenLayer, native ethereum re-stakers, who are also block-proposers, can provide strong guarantees on event-driven inclusion at the risk of getting slashed.
Notes: This could also be a major step forward for account abstraction, allowing miners to effectively pay the gas for this transaction if they wanted to. Event driven activations stuff for liquidations, collateral refilling aren’t as interesting but we could check the crazy stuff people do for MEV to see if something would be interesting there.&lt;/p&gt;
&lt;p&gt;Opt-In MEV Management : We note that a manifold variety of opt-in MEV management methods become feasible under EigenLayer, including Proposal-Builder Separation, MEV smoothing, threshold encryption for transaction inclusion. As a simple example, MEV smoothing can be built on top of EigenLayer by a committee of ETH restakers who then equally share their MEV. Any restakers who deviate from the prescribed MEV smoothing behavior can be slashed. &lt;/p&gt;
&lt;p&gt;Sidechains with ultra-low latency: EigenLayer allows the creation of re-staked sidechains where ETH re-stakers can participate in new consensus protocols, some of which have very low latency and very high throughput. Of course, a precondition for opting in to such sidechains is a higher computational power.&lt;/p&gt;
&lt;p&gt;Single-slot finality It is possible to imagine single-slot finality, where nodes sign off on the finality of block via an opt-in mechanism EigenLayer. The core idea would be that nodes who have restaked can now attest that they will not build on a chain that does not include the testified block, thus creating a potential finality pathway. Designing it so that it is truly opt-in and does not break the consensus protocol, is an important direction of research
Notes: useful for IBC, but requires much more to be practical&lt;/p&gt;
&lt;p&gt;Risk Harbor&lt;/p&gt;
&lt;h2 id=&quot;bullish-on-idea&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bullish-on-idea&quot; aria-label=&quot;bullish on idea permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bullish on Idea&lt;/h2&gt;
&lt;p&gt;Morpho/Ajna/P2P lending
Waymont
Beanstalk
Eigenlayer
Primitive finance
UXD protocol
Nomad
On chain foreign exchange or interest rate swaps
Gammaswap
Lien protocol
Sudoswap
Nounsdao
Risk swap: Use bond curves to swap between underwriting capital and protection purchase. Triggers when something defaults&lt;/p&gt;
&lt;h2 id=&quot;bullish-on-team&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bullish-on-team&quot; aria-label=&quot;bullish on team permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bullish on Team&lt;/h2&gt;
&lt;p&gt;Crocswap&lt;/p&gt;
&lt;h2 id=&quot;other&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other&quot; aria-label=&quot;other permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other&lt;/h2&gt;
&lt;p&gt;Cosmos
Independent Security Auditors&lt;/p&gt;
&lt;h1 id=&quot;everything-im-bearish-on&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#everything-im-bearish-on&quot; aria-label=&quot;everything im bearish on permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Everything I’m bearish on&lt;/h1&gt;
&lt;h2 id=&quot;bearish-on-team-and-idea&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bearish-on-team-and-idea&quot; aria-label=&quot;bearish on team and idea permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bearish on Team and Idea&lt;/h2&gt;
&lt;p&gt;Nexus Mutual&lt;/p&gt;
&lt;h2 id=&quot;bearish-on-team&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bearish-on-team&quot; aria-label=&quot;bearish on team permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bearish on Team&lt;/h2&gt;
&lt;p&gt;Canto - Just because of my work on Evmos
Saddle Finance - poor code quality&lt;/p&gt;
&lt;h2 id=&quot;bearish-on-idea&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bearish-on-idea&quot; aria-label=&quot;bearish on idea permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bearish on Idea&lt;/h2&gt;
&lt;p&gt;MEV
Waves(the blockchain)&lt;/p&gt;
&lt;h2 id=&quot;other-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-1&quot; aria-label=&quot;other 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other&lt;/h2&gt;
&lt;h1 id=&quot;things-you-might-not-have-know&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#things-you-might-not-have-know&quot; aria-label=&quot;things you might not have know permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Things you might not have know&lt;/h1&gt;
&lt;h3 id=&quot;tvl-is-fake&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tvl-is-fake&quot; aria-label=&quot;tvl is fake permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;TVL is fake&lt;/h3&gt;
&lt;p&gt;People fake TVL all the time. Whether through recursive lending/borrowing, liquidity mining rewards, or a waves play, what you see if often not what you get. However, some projects and firms take this one step further where they make deals to pledge some portion of project tokens in exchange for a certain TVL amount. Some examples of this include platypus finance, where alameda deposited hundreds of millions in stablecoins and dumped the tokens that they received from the team.&lt;/p&gt;
&lt;h3 id=&quot;random-list-of-protocols-that-probably-have-an-exploit-or-two-in-them&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#random-list-of-protocols-that-probably-have-an-exploit-or-two-in-them&quot; aria-label=&quot;random list of protocols that probably have an exploit or two in them permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Random list of protocols that probably have an exploit or two in them&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://defillama.com/forks/Compound&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Compound forks&lt;/a&gt; on weird EVM alt L1s. Compound is safe protocol. Compound forks are not safe protocols. There are a wide variety of possible exploits on a compound fork:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;if you use bad oracles, you will get flash loaned and drained&lt;/li&gt;
&lt;li&gt;even if you have flash loan checks, the prices of the least liquid token can probably be manipulated, as there usually isn’t too much liquidity on an alt L1.&lt;/li&gt;
&lt;li&gt;If you have a single ERC-777 or ERC-677 token, someone will hit you with a reentrancy attack&lt;/li&gt;
&lt;li&gt;If you use an old version of the compound v2 codebase, you will get hit with the &lt;code class=&quot;language-text&quot;&gt;.transfer()&lt;/code&gt; hack, the same one that stole 80 million from the Fei pool in Rari&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;tiers-of-defi-teams&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tiers-of-defi-teams&quot; aria-label=&quot;tiers of defi teams permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Tiers of DeFi Teams&lt;/h3&gt;
&lt;p&gt;There’s basically three tiers of DeFi Teams
Tier 1: 30+ people, basically the MakerDAOs and the Uniswaps of the world. They usually have strong PMF and are heavily recognized, they ship open sourced code in addition to working on their project, and generally try to advance the industry in addition to their own projects.&lt;/p&gt;
&lt;p&gt;Tier 2: Top End: Frax Finance, Bottom End: Saddle Finance. This is a barebones team, where there is at least one person covering each of the major facets required to run a DeFi project. They usually have one of each of the following: Solidity Engineer, Frontend Engineer, Designer(usually contracted), business lead(basically takes all the calls), community lead(sometimes combined with business lead, basically someone to sit in discord all day), and founder. Fun fact, legal action will destroy them, as they have no bandwidth or money to deal with that.&lt;/p&gt;
&lt;p&gt;Tier 3: This is either a solo dev or an anon “team” of devs. It usually takes them a while to get going since they are basically a one man show, telegram takes a while for a response, things don’t ship very quickly, tweets usually happen at most once a day, etc. I know this because I did this in the past.&lt;/p&gt;
&lt;h3 id=&quot;list-of-novel-or-interesting-defi-protocols-you-probably-havent-heard-of&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#list-of-novel-or-interesting-defi-protocols-you-probably-havent-heard-of&quot; aria-label=&quot;list of novel or interesting defi protocols you probably havent heard of permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;List of Novel or Interesting Defi Protocols you probably haven’t heard of&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://www.gamma.xyz/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.gamma.xyz/&lt;/a&gt;
&lt;a href=&quot;https://end.gg/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://end.gg/&lt;/a&gt;
&lt;a href=&quot;https://www.arpeggi.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.arpeggi.io/&lt;/a&gt;
&lt;a href=&quot;https://sloika.xyz/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://sloika.xyz/&lt;/a&gt;
&lt;a href=&quot;https://aspect.co/status&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://aspect.co/status&lt;/a&gt;
&lt;a href=&quot;https://beta.catalog.works/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://beta.catalog.works/&lt;/a&gt;
&lt;a href=&quot;https://koop.xyz/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://koop.xyz/&lt;/a&gt;
&lt;a href=&quot;https://www.defifranc.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.defifranc.com/&lt;/a&gt;
&lt;a href=&quot;https://fantasm.finance/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://fantasm.finance/&lt;/a&gt;
Timeless finance LIT token distribution
tom howard is building stablecoins in cosmos
gyroscope&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Lessons from a UC Berkeley 4.0]]></title><description><![CDATA[Actually Useful Study Tips]]></description><link>https://albertsu.netlify.app//posts/reflections/lessons-from-a-uc-berkeley-4.0</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/reflections/lessons-from-a-uc-berkeley-4.0</guid><pubDate>Fri, 20 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Note: I am not the UC Berkeley 4.0 :{&lt;/p&gt;
&lt;h3 id=&quot;midterm-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#midterm-1&quot; aria-label=&quot;midterm 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Midterm 1&lt;/h3&gt;
&lt;p&gt;Always over study for midterm 1, you don’t know how well your classmates will do on the tests nor the structure and format for the tests, thus, you need to be extra prepared.&lt;/p&gt;
&lt;h3 id=&quot;one-day-before-the-exam-you-havent-started-studying-what-do-you-do&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#one-day-before-the-exam-you-havent-started-studying-what-do-you-do&quot; aria-label=&quot;one day before the exam you havent started studying what do you do permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;One Day Before the Exam, you haven’t started studying. What do you do?&lt;/h3&gt;
&lt;p&gt;Watch every single lecture and take notes. If you have time left, “Give your brain the tools to do the problems, eventually when you are under enough pressure, your brain will do it for you.”&lt;/p&gt;
&lt;p&gt;“If you do practice problems, you will be really good at the practice problems. But if you get a problem that you haven’t seen before, you won’t get it. Going over the lecture and notes is much more important.”&lt;/p&gt;
&lt;p&gt;“Optimally, go through all the lectures and take notes, then go back and fill in the notes(since if you are watching lecture it should move too fast for you. Then do the discussions which should now be pretty easy(except if the discussion is full of old exam questions). Then, you are chilling, you don’t even need to take practice tests” A day or two before the exam, take 2-3 hours and split your cheat sheet into the number of lectures, then fill in your cheat sheet according to the lecture.”&lt;/p&gt;
&lt;h3 id=&quot;why-do-you-succeed-when-other-berkeley-students-fail&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-do-you-succeed-when-other-berkeley-students-fail&quot; aria-label=&quot;why do you succeed when other berkeley students fail permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why do you succeed when other berkeley students fail?&lt;/h3&gt;
&lt;p&gt;Up to +1 std deviations, it’s just work. Up to +2 std deviations, it’s just talent. So many kids are afraid of leaving questions blank, in 170 and 162, I left one subpart blank. Don’t skip questions, but it is coding, its fine to skip. If the point total is too little for the work, come back to it later.&lt;/p&gt;
&lt;h3 id=&quot;do-you-forget-stuff-after-classes-are-over&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#do-you-forget-stuff-after-classes-are-over&quot; aria-label=&quot;do you forget stuff after classes are over permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Do you forget stuff after classes are over?&lt;/h3&gt;
&lt;p&gt;No, I just remember stuff.&lt;/p&gt;
&lt;h3 id=&quot;translating-skills-from-class-to-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#translating-skills-from-class-to-work&quot; aria-label=&quot;translating skills from class to work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Translating skills from class to work?&lt;/h3&gt;
&lt;p&gt;“I’ve never tried leetcode”&lt;/p&gt;
&lt;h3 id=&quot;homeworks&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#homeworks&quot; aria-label=&quot;homeworks permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Homeworks&lt;/h3&gt;
&lt;p&gt;“I just sit down and do it starting at 8 in the morning the day it is due. If I’m not feeling it, I just won’t do the homework” Note: This man didn’t do 3 homeworks in algorithms even though you only have two homework drops&lt;/p&gt;
&lt;h3 id=&quot;piazza&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#piazza&quot; aria-label=&quot;piazza permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Piazza&lt;/h3&gt;
&lt;p&gt;“I fucking hate piazza(online forum to ask questions) cause they are fucking dumbasses on there. 170 was the first time since the problems are too much to do by yourself. When people leave how they’ve done problems, then that is useful to look. ” It’s better to talk to people in real life that you know to bounce ideas off of.&lt;/p&gt;
&lt;h3 id=&quot;have-you-ever-gotten-worse-than-an-a-in-a-class&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#have-you-ever-gotten-worse-than-an-a-in-a-class&quot; aria-label=&quot;have you ever gotten worse than an a in a class permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Have you ever gotten worse than an A in a class?&lt;/h3&gt;
&lt;p&gt;Yeah, in AP Calc B. Because I played too many video games&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Probability in Electrical Engineering and Computer Science]]></title><description><![CDATA[Real applications of probability]]></description><link>https://albertsu.netlify.app//posts/academics/probability</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/academics/probability</guid><pubDate>Tue, 10 Jan 2023 23:46:37 GMT</pubDate><content:encoded>&lt;p&gt;Introduction to Probability, 2nd Edition
Follows the course, can borrow from engineering library&lt;/p&gt;
&lt;p&gt;TODO:
Set calendar for homework self grades and resubmission time
Set midterm time on calendar
Choose discussion time
Countable vs uncountable&lt;/p&gt;
&lt;h2 id=&quot;probability-math--a-way-of-thinking-about-uncertainty&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#probability-math--a-way-of-thinking-about-uncertainty&quot; aria-label=&quot;probability math  a way of thinking about uncertainty permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Probability: Math + a way of thinking about uncertainty&lt;/h2&gt;
&lt;p&gt;Humans are naturally good at thinking about probability. For example, you can easily walk down a crowded street and estimate what path allows you to avoid bumping into people. However, humans are pretty awful at turning those innate estimates into quantifiable numbers. The goal is to take the natural probability estimation into something that a robot can understand.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Quantify + Model&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Inference. Humans are also really good at taking in noisy observations and infer what is really happening. &lt;/p&gt;
&lt;p&gt;How do I generate some image from AI? Take a natural image and repeatedly add noise to it. You then end up with an image of pure noise. The idea behind stable diffusion and dalle-2 is to reverse this process. We generate a bunch of noise, then reduce noise until we end up with a image.&lt;/p&gt;
&lt;p&gt;Modern theory of probability has an axiomatic starting point. Before the 1930s, probability was a heuristic field.
All of probability are logical deductions from the starting point.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Probability space:&lt;/em&gt; A probability space (Ω, F, P) is a triple.
Ω is a set, the sample space.
F is a family of subsets of Ω, called events
P is a probability measure&lt;/p&gt;
&lt;p&gt;Rules: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;F is a σ-algebra, it contains Ω itself. F is closed under complements and countable unions. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If A ∈ F, then any of A’s complements belong to F &lt;/li&gt;
&lt;li&gt;countable unions: If A1, A2, … ∈ F, then the union of Ai ∈ F&lt;/li&gt;
&lt;li&gt;By DeMorgan’s Laws, this implies that F is also closed under countable intersections&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;P is a function that maps events to a number between 0 and 1. &lt;code class=&quot;language-text&quot;&gt;P: F -&gt; [0,1]&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Probability measures must obey Komogorov Axioms&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;P(A) &gt;= 0&lt;/code&gt; Probability of any event must be non-negative&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;P(Ω) = 1&lt;/code&gt; The probability of any outcome occuring must be equal to 1&lt;/li&gt;
&lt;li&gt;σ-additivity aka countable additivity. If A1, A2, … is a countable sequence of events and disjoint, then &lt;code class=&quot;language-text&quot;&gt;P(U) = ΣP(Ai)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;counterexample: &lt;code class=&quot;language-text&quot;&gt;P = Unif(0,1)&lt;/code&gt;, then P({x}) = 0 for x ∈ [0,1]. If &lt;code class=&quot;language-text&quot;&gt;1 = P([0,1])&lt;/code&gt;, then &lt;code class=&quot;language-text&quot;&gt;Σ P({x}) = 0&lt;/code&gt; &amp;#x3C;- Dive into this later&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Examples of the Above Rules&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Flip a coin with bias P(Heads with probability p, Tails with probability 1-p). &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Ω = {H, T} The sample space is just heads and tables&lt;/li&gt;
&lt;li&gt;F = 2 ^ σ = {H, T, Ø, {H, T}} These are all subsets of σ&lt;/li&gt;
&lt;li&gt;P(H) = p, P(T) = 1-p, P(Ø) = 0, P({H, T}) = 1 Why are Ø and {H, T} here?&lt;/li&gt;
&lt;li&gt;We then want to create an experiment of n “independent” flips. Is our vocabulary rich enough for this? no&lt;/li&gt;
&lt;li&gt;Ω = {H, T}^n, F = 2^Ω, P(f1, f2, … , fn) = p^{number of flips fi = H} * (1-p)^{number of flips fi = T}&lt;/li&gt;
&lt;li&gt;There can be multiple answers for a probability space. It just needs to be rich enough to capture all the probabilities&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ω now equals all possible configurations of atoms in the universe. How do we represent this?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Let A = {set of configurations that lead to flip heads}&lt;/li&gt;
&lt;li&gt;Let B = {set of configurations that lead to flip tails}&lt;/li&gt;
&lt;li&gt;F = {Ø, A, B, Ω = {A U B}}&lt;/li&gt;
&lt;li&gt;P(A) = p, P(B) = 1-p, P(Ø) = 0, P(Ω) = 1&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note: The probability space is usually implicitly described, except for HW 1.
Lol&lt;/p&gt;
&lt;h2 id=&quot;all-of-the-rules-of-probability-you-are-likely-familiar-with-are-consequences-of-the-three-axioms&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#all-of-the-rules-of-probability-you-are-likely-familiar-with-are-consequences-of-the-three-axioms&quot; aria-label=&quot;all of the rules of probability you are likely familiar with are consequences of the three axioms permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;All of the rules of probability you are likely familiar with are consequences of the three axioms.&lt;/h2&gt;
&lt;p&gt;Ex: If &lt;code class=&quot;language-text&quot;&gt;A ∈ F&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;P(A^C) = 1 - P(A)&lt;/code&gt;. The probability of A’s complement is 1 - probability of A.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Since F is σ algebra, then A^C ∈ F. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A U A^C. A and A complement is a disjoint union equal to Ω&lt;/li&gt;
&lt;li&gt;1 = P(Ω) Using axiom 2&lt;/li&gt;
&lt;li&gt;P(A U A^C) = P(A) + P(A^C) Using Axiom 3&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ex: If A and B are events and A is a subset of B, then &lt;code class=&quot;language-text&quot;&gt;P(A) &amp;lt;= P(B)&lt;/code&gt;
B = A U (B \ A). B is equal to the disjoint union of A and B minus the elements of A
P(B) = P(A U (B \ A)) =&gt; P(A) + P(B\A)  Using axiom 3
P(A) + P(B\A) &gt;= P(A) Using axiom 1&lt;/p&gt;
&lt;p&gt;Ex: If A and B are events, then P(A U B) = P(A) + P(B) - P(A ∩ B). Aka inclusion exclusion principle
Proof: &lt;code class=&quot;language-text&quot;&gt;AUB, A∩B ∈ F&lt;/code&gt;
A U B = B U (A \ B)
P(A U B) = P(B) + P(A\(A∩B)) Using axiom 3
P(B) + P(A\(A∩B)) = P(B) + P(A) - P(A ∩B) Using Axiom 3&lt;/p&gt;
&lt;p&gt;Ex: Ω = countable set
F = 2 ^ Ω, each individual is an event {w} ∈ F, for all w ∈ Ω
P(A) = Σ for all A ⊆ Ω
This is a discrete sample space.&lt;/p&gt;
&lt;p&gt;Ex: Law of total probability. If A1, A2, …, partition Ω, then (Ω = U Ai). Mutually exclusive, collectively exhaustive.
Then, for any B ∈ F, then &lt;code class=&quot;language-text&quot;&gt;P(B) = Σ P(B ∩ Ai)&lt;/code&gt;
B = U(Ai ∩ B) then apply axiom 3&lt;/p&gt;
&lt;p&gt;The goal of probability is to take complicated things and use that to approximate them into multiple simpler events.&lt;/p&gt;
&lt;p&gt;Mathematicians: Given a probability space(model), what can I say about outcomes of experiments that derive from this model?
Statistician: Given outcomes, how do I choose a good model(probability space)?
Engineers: Given a real world problem, how do I choose a model that captures the essence of the model and then use the model to draw insight.&lt;/p&gt;
&lt;h1 id=&quot;lecture-2-conditional-probability-independence-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lecture-2-conditional-probability-independence-random-variables&quot; aria-label=&quot;lecture 2 conditional probability independence random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lecture 2: Conditional Probability, Independence, Random Variables&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Conditional Probability:&lt;/strong&gt; If &lt;code class=&quot;language-text&quot;&gt;B ∈ F&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;P(B) &gt; 0&lt;/code&gt;, then conditional probability P(A|B) = P(A ∩ B) / P(B)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Intuition&lt;/em&gt;: Probability A occurs given we know that B occurred&lt;/p&gt;
&lt;p&gt;Formal Definition: P(.|B) gives a restriction of our model (Ω, F, P) to those samples in B
If &lt;code class=&quot;language-text&quot;&gt;(B, F|B, P(.|B))&lt;/code&gt; is a probability space itself, where &lt;code class=&quot;language-text&quot;&gt;F|B = \{A ∩ B: A ∈ F\}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Ex.&lt;/em&gt; If A1, A2, … ∈ F, P(Ai) &gt; 0, A partion Ω
&lt;code class=&quot;language-text&quot;&gt;P(B) = Σ P(B ∩ Ai) = Σ P(B|Ai) * P(Ai)&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&quot;bayes-rule&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bayes-rule&quot; aria-label=&quot;bayes rule permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bayes Rule&lt;/h2&gt;
&lt;p&gt;Sometimes, it’s easy to express P(B|A), but we are really interested in P(A|B)
Let A be the state of the experiment, B be the observation data&lt;/p&gt;
&lt;p&gt;P(A|B) - given the observation, we want the state. This is the task of inference.&lt;/p&gt;
&lt;p&gt;Suppose we forgot Bayes Rule, let’s try to recreate it from definition of conditional probability
&lt;code class=&quot;language-text&quot;&gt;P(A|B) = P(B ∩ A) / P(B) = P(A) * P(B|A) / P(B)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Ex.&lt;/em&gt; Suppose we have the following model: 85% of students got a pass, 15% of students got a no pass. 60% students that got passes went to lecture, 40% of students did not go to lecture. 10% of students that got no passes went to lecture, 90% didn’t go to lecture.&lt;/p&gt;
&lt;p&gt;We want P(NP | N) / P(NP | Y). How much more likely are you to NP when you don’t attend lecture vs when you do attend lecture?
P(NP ∩ N) / P(NP ∩ Y) * P(Y) / P(N)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Ex.&lt;/em&gt; Suppose we roll two dice and the sum is 10. What is the probability roll 1 was = 4?&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;B = \{Sum of rolls = 10\}
A = \{first roll is 4\}

P(A|B) = P(A ∩ B) / P(B)
       = P({First roll is 4, sum of rolls is 10}) / P({sum of rolls is 10})
       = P({first: 4, second: 6}) / P({(4,6), (5,5), (6,4)})
       = (1/36) / (3/36)
       = 1/3&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;conditioning-also-allows-us-to-usefully-decompose-intersections-of-events&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conditioning-also-allows-us-to-usefully-decompose-intersections-of-events&quot; aria-label=&quot;conditioning also allows us to usefully decompose intersections of events permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conditioning also allows us to usefully decompose intersections of events.&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Ex.&lt;/em&gt; Consider event A1 … An
P(∩ A) = P(A&lt;sub&gt;1&lt;/sub&gt; | ∩&lt;sup&gt;n&lt;/sup&gt;&lt;sub&gt;i = 2&lt;/sub&gt; A&lt;sub&gt;i&lt;/sub&gt;) P (∩ A&lt;sub&gt;i&lt;/sub&gt;)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Ex.&lt;/em&gt; Given n people in a room, what is the probability that more than 2 people share a birthday?&lt;/p&gt;
&lt;p&gt;A&lt;sub&gt;i&lt;/sub&gt; = {person i does not share a birthday with any of the people j = 1, …, i-1}&lt;/p&gt;
&lt;p&gt;P(A&lt;sub&gt;i&lt;/sub&gt; | ∩ &lt;sup&gt;i-1&lt;/sup&gt;&lt;sub&gt;j=1&lt;/sub&gt; A&lt;sub&gt;j&lt;/sub&gt;) = (365 - (i-1)) / 365&lt;/p&gt;
&lt;p&gt;This is because the person needs to land in one of the days not in the 365.
P(no shared birthdays) = P(∩ A&lt;sub&gt;i&lt;/sub&gt;)&lt;/p&gt;
&lt;p&gt;Use 1-x &amp;#x3C;= e^-x.
Approximate using taylor series&lt;/p&gt;
&lt;p&gt;Let n = 23 - there are 23 kids in a class.
P(shared birthday) &gt;= 1 - e^((i-1)/365))&lt;/p&gt;
&lt;h2 id=&quot;independence&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#independence&quot; aria-label=&quot;independence permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Independence&lt;/h2&gt;
&lt;p&gt;Events A, B are independent if P(A ∩ B) = P(A) * P(B)
Disjoint events are not independent
&lt;em&gt;Note:\&lt;/em&gt; in a special case where P(A) &gt; 0: A,B: dependent &amp;#x3C;=&gt; P(B|A) = P(B)&lt;/p&gt;
&lt;p&gt;In general, collection A&lt;sub&gt;1&lt;/sub&gt;, A&lt;sub&gt;2&lt;/sub&gt;, … ∈ F are independent events if P(∩&lt;sub&gt;i ∈ S&lt;/sub&gt; A&lt;sub&gt;i&lt;/sub&gt;) = ∏ &lt;sub&gt;i ∈ S&lt;/sub&gt; P(A&lt;sub&gt;i&lt;/sub&gt;) for all finite sets of indices S&lt;/p&gt;
&lt;p&gt;If A&lt;sub&gt;1&lt;/sub&gt;, A&lt;sub&gt;2&lt;/sub&gt;, … ∈ F are independent, then B&lt;sub&gt;1&lt;/sub&gt;, B&lt;sub&gt;2&lt;/sub&gt;, … are independent, where each A&lt;sub&gt;i&lt;/sub&gt; = B&lt;sub&gt;i&lt;/sub&gt; or B&lt;sub&gt;i&lt;/sub&gt;&lt;sup&gt;C&lt;/sup&gt;
Intuitively, we assume that knowing A means we know A’s complement&lt;/p&gt;
&lt;p&gt;∩&lt;sub&gt;i=2&lt;/sub&gt;&lt;sup&gt;n&lt;/sup&gt; A&lt;sub&gt;i&lt;/sub&gt;
∏P(Ai) = P(∩ Ai) = P(∩) + P(A1)
(1- P(Ai)) ∏ P(Ai) = P(A1^C ∩ ∏&lt;sub&gt;i=2&lt;/sub&gt;Ai)
This shows A&lt;sub&gt;1&lt;/sub&gt;&lt;sup&gt;C&lt;/sup&gt;, A&lt;sub&gt;2&lt;/sub&gt;, … , A&lt;sub&gt;n&lt;/sub&gt; are independent
Therefore, B&lt;sub&gt;1&lt;/sub&gt;, B&lt;sub&gt;2&lt;/sub&gt;, … , B&lt;sub&gt;n&lt;/sub&gt; are independent&lt;/p&gt;
&lt;h3 id=&quot;conditional-independence&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conditional-independence&quot; aria-label=&quot;conditional independence permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conditional Independence&lt;/h3&gt;
&lt;p&gt;Often times we have two events that we think of as independent but aren’t. There might be a confounding variable C
If A,B,C are such that P(C) &gt; 0 and P(A∩B|C) = P(A|C) P(B|C), then A,B are said to be conditionally independent given C&lt;/p&gt;
&lt;p&gt;Consider two coins with bias p!=q
Pick a coin at random, and flip twice. H(i) = Event that flip i is heads
Are the two coinflips independent? No. If p is 1 and q is 0, then we know what the next coin flip is given our first coin flip.&lt;/p&gt;
&lt;p&gt;P(H&lt;sub&gt;i&lt;/sub&gt;) = p + q / 2
P(H&lt;sub&gt;1&lt;/sub&gt; ∩ H&lt;sub&gt;2&lt;/sub&gt;) = p&lt;sup&gt;2&lt;/sup&gt; + q&lt;sup&gt;2&lt;/sup&gt; / 2 != P(H&lt;sub&gt;1&lt;/sub&gt;) P(H&lt;sub&gt;2&lt;/sub&gt;) = (p+q)&lt;sup&gt;2&lt;/sup&gt; / 2
C = {pick coin p} H&lt;sub&gt;1&lt;/sub&gt;, H&lt;sub&gt;2&lt;/sub&gt; conditionally independent given C&lt;/p&gt;
&lt;p&gt;TODO:
Set calendar for homework self grades and resubmission time
Set midterm time on calendar
Countable vs uncountable&lt;/p&gt;
&lt;h1 id=&quot;random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#random-variables&quot; aria-label=&quot;random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Random Variables&lt;/h1&gt;
&lt;p&gt;Password: Teapot&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Def:&lt;/em&gt; A random variable X is a function X: Ω -&gt; R. It implies it is valid to write things like P(X &amp;#x3C;= 3). P(X &amp;#x3C;=3) is shorthand for P({ω: X(ω) &amp;#x3C;= 3})
Random conditions have a measurability condition&lt;/p&gt;
&lt;p&gt;Often times we want to compute more complex probabilities, such as P(α &amp;#x3C; X &amp;#x3C; β).
{ω: X(ω) &amp;#x3C; β} = U&lt;sub&gt;n &gt;=1&lt;/sub&gt;{ω: X(ω) &amp;#x3C; β -1/n} ∈ F
{ω: X(ω) &gt; α} = {ω: X(ω) &amp;#x3C;= α}&lt;sup&gt;C&lt;/sup&gt; ∈ F
P(X ∈ B) for pretty much any B(subset of R) that you want
Here, the technical name for B is &lt;em&gt;Borel sets&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Another consequence of the definition of random variables:
If X,Y are random variables on (Ω, F, P):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;X+Y is a random variable&lt;/li&gt;
&lt;li&gt;X*Y is a random variable&lt;/li&gt;
&lt;li&gt;|X|&lt;sup&gt;p&lt;/sup&gt; is a random variable&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;probability-distributions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#probability-distributions&quot; aria-label=&quot;probability distributions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Probability Distributions&lt;/h2&gt;
&lt;p&gt;For any random variable X on probability space (Ω, F, P), we can define its distribution(aka its “law”) L&lt;sub&gt;x&lt;/sub&gt; via L&lt;sub&gt;x&lt;/sub&gt;(B) := P(X ∈ B), B ∈ R
For example, L&lt;sub&gt;x&lt;/sub&gt;({x}) = P(X=x)&lt;/p&gt;
&lt;p&gt;The histogram of values that a random variable would take.&lt;/p&gt;
&lt;p&gt;Similar to a probability measure.&lt;/p&gt;
&lt;p&gt;In practice, we often describe our model for experimental outcomes in terms of distributions. Given this, I can always construct a probability space and random variable X that has this distribution.&lt;/p&gt;
&lt;p&gt;Ex: Given distribution L, we can consider probability space (R, B, L) and random variable X(ω)=x, ω ∈ Ω = R
Distribution of X&lt;/p&gt;
&lt;p&gt;Important Class of Random Variables;
&lt;em&gt;Discrete Random Variables&lt;/em&gt;: A random variable that takes countably many values
Ex: X = flip of a p-biased coin. This is a bernoulli distribution with probability p&lt;/p&gt;
&lt;p&gt;X = roll a dice. This is a uniform distribution over {1,2,3,4,5,6}
X = number of coin flips until I flip heads. Geometric Distribution
X = number of heads in n flips. Binomial Distribution (n, p)&lt;/p&gt;
&lt;p&gt;In case of a discrete random variable X, the distribution of X can be summarized by its probability mass function.
P&lt;sub&gt;x&lt;/sub&gt;(x) := P({X=x}) = P{ω: X(ω) = x}&lt;/p&gt;
&lt;p&gt;By axioms, p&lt;sub&gt;x&lt;/sub&gt;(x) &gt;= 0 and Σp&lt;sub&gt;x&lt;/sub&gt;(x) = 1&lt;/p&gt;
&lt;h3 id=&quot;joint-distributions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#joint-distributions&quot; aria-label=&quot;joint distributions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Joint Distributions&lt;/h3&gt;
&lt;p&gt;For a pair of discrete random variables X,Y defined on the common probability space (Ω, F, P), their joint distribution is:
summarized by the join probability mass function defined via
P&lt;sub&gt;xy&lt;/sub&gt; = P(X=x, Y=y) = P({ω: X(ω) = x &amp;#x26;&amp;#x26; Y(ω) = y}) = P({ω: X(ω)} ∩ {ω: Y(ω) = y})
We can obtain the “marginal” distributions by P&lt;sub&gt;x&lt;/sub&gt;(x) = Σ P&lt;sub&gt;xy&lt;/sub&gt;(x,y) using the law of total probability Σ P(x) = 1&lt;/p&gt;
&lt;h2 id=&quot;independent-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#independent-random-variables&quot; aria-label=&quot;independent random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Independent Random Variables&lt;/h2&gt;
&lt;p&gt;Def: Discrete Random Variables X,Y are independent if their probability mass function factors into their marginals
P&lt;sub&gt;xy&lt;/sub&gt;(x,y) = P&lt;sub&gt;x&lt;/sub&gt;(x)P&lt;sub&gt;y&lt;/sub&gt;(y)&lt;/p&gt;
&lt;p&gt;This is equivalent to saying {ω: X(ω) = x}) and {ω: Y(ω) = y}) are independent events for all x,y&lt;/p&gt;
&lt;p&gt;Examples of Joint Distributions:
X = {0 if patient tests negative with probability 0.9, 1 if patient tests positive with probability 0.1}
Y = {0 if patient is negative, 1 if patient is positive}&lt;/p&gt;
&lt;p&gt;We know the false positive rate of the test is 5%, the false negative rate of test is 1%&lt;/p&gt;
&lt;p&gt;Question: What is P&lt;sub&gt;XY&lt;/sub&gt;?
I test my patient. The test is either negative(.9) or positive(.1).&lt;/p&gt;
&lt;h2 id=&quot;expectation---used-for-discrete-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#expectation---used-for-discrete-random-variables&quot; aria-label=&quot;expectation   used for discrete random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Expectation - Used for discrete random variables&lt;/h2&gt;
&lt;p&gt;Takes in a random variable, spits out a distribution
For a discrete random variable X on (Ω, F, P), we define its expectation E(X) = ΣxP{X=x} = Σxp&lt;sub&gt;x&lt;/sub&gt;(x)&lt;/p&gt;
&lt;p&gt;Ex: If X Ω = {0,1}&lt;sup&gt;n&lt;/sup&gt;, P({ω}) = p&lt;sup&gt;{number of heads}&lt;/sup&gt; (1-p)&lt;sup&gt;{number of tails}&lt;/sup&gt;
ie a sequence of independent p biased coin flips&lt;/p&gt;
&lt;p&gt;X(ω) = {ω = 9}. &amp;#x3C;= Number of heads
E[X] = Σ{i : ω&lt;sub&gt;i&lt;/sub&gt;= 1}, p&lt;sup&gt;{i : ω&lt;sub&gt;i&lt;/sub&gt;= 1}&lt;/sup&gt; (1-p)&lt;sup&gt;{i : ω&lt;sub&gt;i&lt;/sub&gt;= 1}&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;= Σ&lt;sub&gt;k=0&lt;/sub&gt;&lt;sup&gt;n&lt;/sup&gt; (n k) p&lt;sup&gt;k&lt;/sup&gt; (1-p)&lt;sup&gt;n-k&lt;/sup&gt; = np&lt;/p&gt;
&lt;p&gt;The most important property of expectation is that it is linear.
Expectation is an operator, it takes a function and spits out a number, just like an integral.
Just like how integrals are linear, expectation is also linear.&lt;/p&gt;
&lt;p&gt;The most important and only property of expectation &lt;code class=&quot;language-text&quot;&gt;E[X+Y] = E[X] + E[Y]&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&quot;linearity-of-expectation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#linearity-of-expectation&quot; aria-label=&quot;linearity of expectation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Linearity of Expectation&lt;/h3&gt;
&lt;p&gt;If X,Y random variables defined on a common probability space. &lt;code class=&quot;language-text&quot;&gt;E[aX + bY] = aE[X] + bE[Y]&lt;/code&gt; &amp;#x3C;= There is no need for expectation to be independent or discrete.&lt;/p&gt;
&lt;p&gt;LemmaL E[g(z)] = Σ g(z) p&lt;sub&gt;z&lt;/sub&gt;(z)&lt;/p&gt;
&lt;p&gt;By the law of the unconscious statistician
E[aX + bY] = Σ(ax + by)P&lt;sub&gt;xy&lt;/sub&gt;(xy) = aΣxP&lt;sub&gt;xy&lt;/sub&gt;(x,y) + bΣxP&lt;sub&gt;xy&lt;/sub&gt;(x,y)&lt;/p&gt;
&lt;h1 id=&quot;sum-of-independent-binomials-variance-covariance-correlation-coefficient-entropy&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sum-of-independent-binomials-variance-covariance-correlation-coefficient-entropy&quot; aria-label=&quot;sum of independent binomials variance covariance correlation coefficient entropy permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sum of Independent Binomials, Variance, Covariance, Correlation Coefficient, Entropy&lt;/h1&gt;
&lt;h2 id=&quot;general-strategy-for-expectation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#general-strategy-for-expectation&quot; aria-label=&quot;general strategy for expectation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;General Strategy for Expectation&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;We introduce indicator random variables and express random variable of interest in terms of the indicators, then use linearity of expectation&lt;/li&gt;
&lt;li&gt;In general, the indicator for event A is denoted by 1&lt;sub&gt;A&lt;/sub&gt;(w) = {0 if ω is not A, 1 if ω is A}
a. 1&lt;sub&gt;A&lt;/sub&gt; = Bernuolli(P(A)), E[1&lt;sub&gt;a&lt;/sub&gt;] = P(A)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Ex: n people put their hats in a bucket, and each draw 1 hat. Let X = number of people who get their own hat back.
X = Σ&lt;sub&gt;i=1&lt;/sub&gt;&lt;sup&gt;n&lt;/sup&gt;1&lt;sub&gt;A&lt;/sub&gt;
A&lt;sub&gt;i&lt;/sub&gt; = {gets own hat back}
E[x] = Σ&lt;sub&gt;i=1&lt;/sub&gt; E[1&lt;sub&gt;M/sub&gt;]= n * 1/n = 1&lt;/p&gt;
&lt;p&gt;Ex: Coupon collector problem
How many on boxes on average do I need to buy before I collect all N coupons
X&lt;sub&gt;i&lt;/sub&gt; = number of boxes to buy to get ith coupon, after getting (i-1)&lt;sup&gt;th
R[].&lt;/p&gt;
&lt;h2 id=&quot;tail-sum-formula-another-way-to-compute-expectation-without-using-linearity-of-expectation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tail-sum-formula-another-way-to-compute-expectation-without-using-linearity-of-expectation&quot; aria-label=&quot;tail sum formula another way to compute expectation without using linearity of expectation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Tail sum formula: Another way to compute expectation without using linearity of expectation.&lt;/h2&gt;
&lt;p&gt;For non-negative integer values random value X&lt;sub&gt;i&lt;/sub&gt;
E[X] = Σ&lt;sub&gt;k=1&lt;/sub&gt;&lt;sup&gt;inf&lt;/sup&gt;P{x=k}&lt;/p&gt;
&lt;p&gt;Proof: write P({x&gt;= k}) = Σ&lt;sub&gt;x&gt;=k&lt;/sub&gt; P{x &gt;= k} = Σ&lt;sub&gt;x&gt;=k&lt;/sub&gt; P(X=x)&lt;/p&gt;
&lt;p&gt;X&lt;sub&gt;1&lt;/sub&gt; = Geom(p), X&lt;sub&gt;2&lt;/sub&gt; = Geom(p)
M = min{X&lt;sub&gt;1&lt;/sub&gt;, X&lt;sub&gt;2&lt;/sub&gt;}
P{M&gt;= k} = P{x&lt;sub&gt;1&lt;/sub&gt;}, P{x&lt;sub&gt;2&lt;/sub&gt;}&lt;/p&gt;
&lt;p&gt;IE[M] = Σ P{x&lt;sub&gt;1&lt;/sub&gt; &gt;= k} P{x&lt;sub&gt;2&lt;/sub&gt;&gt;=k}
= 1 / (1- (1-p)*(1-q)))&lt;/p&gt;
&lt;h2 id=&quot;variance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#variance&quot; aria-label=&quot;variance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Variance&lt;/h2&gt;
&lt;p&gt;Quantitative Notion of variability of X around E[X]
Var(X) = E[(X - E[X])&lt;sup&gt;2&lt;/sup&gt;] = E[X&lt;sup&gt;2&lt;/sup&gt; - 2XE[X] + (E[X])&lt;sup&gt;2&lt;/sup&gt;]= E[X&lt;sup&gt;2&lt;/sup&gt;] - (E[X])&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;If expectation is the price of a stock, variance is the volatility.
Variance is not the only way to measure the variability of a random variable. Another way to measure the variance of a random variable is entropy.
Entropy = Σ P&lt;sub&gt;x&lt;/sub&gt;(X) log(1/P&lt;sub&gt;x&lt;/sub&gt;(X)) = E[log(1/P&lt;sub&gt;x&lt;/sub&gt;(X))]&lt;/p&gt;
&lt;p&gt;Unlike expectation, variance is not linear with respect to its arguments. Var(X+X) = ?
Var(X+Y) != Var(X) + Var(Y)
Var(X+Y) &lt;/p&gt;
&lt;p&gt;By definition of variance
= E[X+Y - E[X] - E[Y]]&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Open up the square using foil
= Var(X) + Var(Y) + 2 E[(X-E[X])(Y-E[Y])]&lt;/p&gt;
&lt;h2 id=&quot;x---exy-ey--covariance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#x---exy-ey--covariance&quot; aria-label=&quot;x   exy ey  covariance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;[X - E[X])(Y-E[Y]) = Covariance&lt;/h2&gt;
&lt;p&gt;Positive covariance means X and Y move in the same direction
If X and Y are independent, covariance is 0&lt;/p&gt;
&lt;p&gt;If X,Y are uncorrelated(covariance of X,Y = 0), then Var(X+Y) = Var(X) + Var(Y)&lt;/p&gt;
&lt;p&gt;Correlation coefficient: Covariance(X, Y) / sqrt(Var(X)*Var(Y)). It is always between -1 and + 1&lt;/p&gt;
&lt;p&gt;Covariance(X,Y) &amp;#x3C;= sqrt(Var(X) * Var(Y))
Using cauchy schwartz inequality, x&lt;sup&gt;T&lt;/sup&gt;y / (||X|| ||Y||) is between [-1, 1]&lt;/p&gt;
&lt;p&gt;E[XY] &amp;#x3C;= E[X&lt;sup&gt;2&lt;/sup&gt;]&lt;sup&gt;1/2&lt;/sup&gt; E[Y&lt;sup&gt;2&lt;/sup&gt;]&lt;sup&gt;1/2&lt;/sup&gt;
E[XY] = Σ P&lt;sub&gt;xy&lt;/sub&gt;(x,y)&lt;sup&gt;1/2&lt;/sup&gt; x * P&lt;sub&gt;xy&lt;/sub&gt;(x,y)&lt;sup&gt;1/2&lt;/sup&gt; y &amp;#x3C;= (Σ&lt;sub&gt;xy&lt;/sub&gt;P&lt;sub&gt;xy&lt;/sub&gt;(x,y)x&lt;sup&gt;2&lt;/sup&gt;)&lt;sup&gt;1/2&lt;/sup&gt; (Σ&lt;sub&gt;xy&lt;/sub&gt;P&lt;sub&gt;xy&lt;/sub&gt;(x,y)y&lt;sup&gt;2&lt;/sup&gt;)&lt;sup&gt;1/2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Let X ~ Binomial(n, p)
X = Σ X&lt;sub&gt;i&lt;/sub&gt; X&lt;sub&gt;i&lt;/sub&gt;Bernuolli(p)
Var(X) = Σ Var(X&lt;sub&gt;i&lt;/sub&gt;) = n Var(X&lt;sub&gt;1&lt;/sub&gt;)&lt;/p&gt;
&lt;h2 id=&quot;poisson-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#poisson-random-variables&quot; aria-label=&quot;poisson random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Poisson random variables&lt;/h2&gt;
&lt;p&gt;Poisson means fish in french. Think number of arrivals when you see poisson
If I dip a net into the water and pull it out, a poisson distribution is a good way to checking how much fish I pull out.&lt;/p&gt;
&lt;p&gt;X ~ Poisson(λ) λ = rate
P&lt;sub&gt;λ&lt;/sub&gt;)(k) = λ&lt;sup&gt;k&lt;/sup&gt;/k! e&lt;sup&gt;-λ&lt;/sup&gt;, k = 0,1,2,…&lt;/p&gt;
&lt;p&gt;Imagine trying to take a bus in berkeley. They are supposed to be at each station every 30 minutes. However, there are times when no buses come for 45 minutes then two buses come in the 46th and 47th minute. You can model the arrival of the buses using a Poisson distribution&lt;/p&gt;
&lt;p&gt;Where does Poisson come from?
Each interval something will arrive with probability p&lt;sub&gt;n&lt;/sub&gt; = λ/n. The probability that something arrives in an interval is X&lt;sub&gt;n&lt;/sub&gt; ~ Binomial(n, p&lt;sub&gt;n&lt;/sub&gt;)&lt;/p&gt;
&lt;p&gt;P(X&lt;sub&gt;n&lt;/sub&gt;=k) = Binomial PMF = (n k) * (λ/n) * (1-λ/n)&lt;sup&gt;n-k&lt;/sup&gt;
= n(n-1)…(n-k+1) &lt;em&gt;(1/n-λ)&lt;sup&gt;k&lt;/sup&gt;&lt;/em&gt; λ&lt;sup&gt;k&lt;/sup&gt;/k! (1-λ/n)&lt;sup&gt;k&lt;/sup&gt;
as n goes to infinity, this distribution converges to a poisson distribution
λ&lt;sup&gt;k&lt;/sup&gt;/k! * e&lt;sup&gt;-k&lt;/sup&gt;&lt;/p&gt;
&lt;h1 id=&quot;continuous-distributions-continuous-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#continuous-distributions-continuous-random-variables&quot; aria-label=&quot;continuous distributions continuous random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Continuous Distributions, Continuous Random Variables&lt;/h1&gt;
&lt;p&gt;Password: Mirror&lt;/p&gt;
&lt;h2 id=&quot;conditional-distributions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conditional-distributions&quot; aria-label=&quot;conditional distributions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conditional Distributions&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;P(A|C) := P(A ∩ C) / P(C)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;When X,Y are discrete: their joint pmf is P&lt;sub&gt;xy&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;P&lt;sub&gt;x|y&lt;/sub&gt;(x|y) := P&lt;sub&gt;x|y&lt;/sub&gt;(x,y) / P&lt;sub&gt;y&lt;/sub&gt;(y) = P({X=x} ∩ {Y=y}) / P({Y=y})&lt;/p&gt;
&lt;p&gt;Since P&lt;sub&gt;x|y&lt;/sub&gt; is a pmf for each y with &lt;code class=&quot;language-text&quot;&gt;P&amp;lt;sub&gt;y&amp;lt;/sub&gt;(y) &gt; 0&lt;/code&gt;, we can take expectation of X with respect to it.&lt;/p&gt;
&lt;p&gt;This is defined as conditional expectation
E[X|Y=y] := Σ&lt;sub&gt;x⊆X&lt;/sub&gt; xP&lt;sub&gt;x|y&lt;/sub&gt;
Once we have the value of Y, what is the value of x?
We usually just write E[X|Y] to denote Σ&lt;sub&gt;x⊆X&lt;/sub&gt; xP&lt;sub&gt;x|y&lt;/sub&gt; evaluated at random variable Y. Thus, the conditional expectation is itself a random variable since it is a function of the random variable Y.&lt;/p&gt;
&lt;h2 id=&quot;tower-property&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tower-property&quot; aria-label=&quot;tower property permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Tower Property&lt;/h2&gt;
&lt;p&gt;Most important property of Conditional expectation: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For all functions f, we can say &lt;code class=&quot;language-text&quot;&gt;E[f(Y)X] = E[f(Y)*E[X|Y]]&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;E[f(Y)X] = Σ&lt;sub&gt;y&lt;/sub&gt; p&lt;sub&gt;y&lt;/sub&gt;(y)f(y) * Σ&lt;sub&gt;x&lt;/sub&gt;P&lt;sub&gt;x|y&lt;/sub&gt;(x|y)&lt;/li&gt;
&lt;li&gt;E[f(Y)X] = Σ&lt;sub&gt;x,y&lt;/sub&gt;P&lt;sub&gt;xy&lt;/sub&gt;(x,y)*f(y)x&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example: Iterated Expectation
E[X] = E[E[X|Y]]
We get this using the tower property by setting f(Y) = 1&lt;/p&gt;
&lt;p&gt;Example: Let N&gt;= 0 be an integer valued random variable. Let’s flip a fair coin N times, and let X = the number of heads.
There are two sources of randomness, the number of flips and whether we get heads or tails.
E[X] = E[E[X|N]]
We can fix the number of coin tosses, and since half of coin tosses are heads
E[X|N] = N / 2
Substitute
E[N/2]
Use linearity of expectation
1/2 E[N]&lt;/p&gt;
&lt;p&gt;Var(X) = E[Var(X|N)] + Var(E[X|N])
Using the same substitution as above of E[X|N] = 1/2
Use binomial theorem for E[Var(X|N)] = E[N/4]. Variance of a binomial = ?
Var(X) = E[N/4] + Var(N/2)
Var(X) = 1/4 * E[N} + 1/2 * Var(N)&lt;/p&gt;
&lt;p&gt;Recall Var(X) = E[X-E[X]&lt;sup&gt;2&lt;/sup&gt;]
Definition: Conditional Variance of X given {Y=y}
Var(X|Y=y) = Σp&lt;sub&gt;x|y&lt;/sub&gt;(x|y)(X-E[X|Y=y])&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Just like conditional expectation, we write Var(X|Y) to denote the random variable evaluated at Y.&lt;/p&gt;
&lt;p&gt;Theorem: Law of total variance&lt;/p&gt;
&lt;p&gt;Var(X) = E[Var(X|Y)] + Var(E[X|Y])&lt;/p&gt;
&lt;p&gt;Proof:&lt;/p&gt;
&lt;p&gt;Var(X) = E[X&lt;sup&gt;2&lt;/sup&gt;] - (E[X])&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;= E[E[X&lt;sup&gt;2&lt;/sup&gt;|Y]] - (E[E[X|Y]])&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;= E[Var(X|Y)] + E[E[X|Y]&lt;sup&gt;2&lt;/sup&gt;] - (E[E[X|Y]])&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;= E[Var(X|Y)] + Var(E[X|Y])&lt;/p&gt;
&lt;p&gt;Now let’s start with Var(X|Y=y)&lt;/p&gt;
&lt;p&gt;= E[X&lt;sup&gt;2&lt;/sup&gt;|Y=y] - (E[X|Y=y])&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;= E[Var(X|Y) + E(X|Y)&lt;sup&gt;2&lt;/sup&gt;] - (E[E[X|Y]])&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;h2 id=&quot;continuous-random-variables-and-continuous-distributions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#continuous-random-variables-and-continuous-distributions&quot; aria-label=&quot;continuous random variables and continuous distributions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Continuous Random Variables and Continuous Distributions&lt;/h2&gt;
&lt;p&gt;Note: Random Variables need not be discrete or continuous or combinations thereof
For a random variable X, we can always define its cumulative distribution function abbreviated CDF via &lt;/p&gt;
&lt;p&gt;F&lt;sub&gt;x&lt;/sub&gt;(X) := P{X&amp;#x3C;=x}&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;F&lt;sub&gt;x&lt;/sub&gt; is nondecreasing &lt;/li&gt;
&lt;li&gt;F&lt;sub&gt;x&lt;/sub&gt;(x) -&gt; {0 if x -&gt; -inf, 1 if x -&gt; inf}&lt;/li&gt;
&lt;li&gt;F&lt;sub&gt;x&lt;/sub&gt; is continuous from the right&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Definition: A random variable X has continuous distribution if there exists a function f&lt;sub&gt;x&lt;/sub&gt; such that &lt;/p&gt;
&lt;p&gt;F&lt;sub&gt;x&lt;/sub&gt;(x) = ∫&lt;sub&gt;-inf&lt;/sub&gt;&lt;sup&gt;x&lt;/sub&gt;f&lt;sub&gt;x&lt;/sub&gt;(u)du&lt;/p&gt;
&lt;p&gt;f&lt;sub&gt;x&lt;/sub&gt; is called the density of X aka a pdf(probability density function)&lt;/p&gt;
&lt;p&gt;For f&lt;sub&gt;x&lt;/sub&gt; to be a density, it just needs to be non-negative and the integral of the density to be equal to 1, since total probability = 1
f&lt;sub&gt;x&lt;/sub&gt; &gt;= 0
∫f&lt;sub&gt;x&lt;/sub&gt;dx = 1&lt;/p&gt;
&lt;h3 id=&quot;continous-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#continous-random-variables&quot; aria-label=&quot;continous random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Continous Random Variables&lt;/h3&gt;
&lt;p&gt;Good for modeling analog signals from the real world.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;time we wait until a bus arrives(Exponential Distribution)&lt;/li&gt;
&lt;li&gt;Voltage across resistor(Gaussian Distribution)&lt;/li&gt;
&lt;li&gt;Phase of a received wireless signal(Uniform Distribution)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Continuous distributions usually described by their density.
X ~ Uniform(a,b) = {1/(b-a) a &amp;#x3C;= x &amp;#x3C;=b, 0 otherwise}
X ~ Exp(λ) = {λe&lt;sup&gt;-λx&lt;/sup&gt; if x&gt;=0, 0 otherwise}
X ~ N(µ,σ&lt;sup&gt;2&lt;/sup&gt;) = 1/sqrt(2pi*σ)exp(-(x-µ)&lt;sup&gt;2&lt;/sup&gt; / 2σ&lt;sup&gt;2&lt;/sup&gt;)&lt;/p&gt;
&lt;h3 id=&quot;jointly-continuous-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#jointly-continuous-random-variables&quot; aria-label=&quot;jointly continuous random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Jointly Continuous Random Variables&lt;/h3&gt;
&lt;p&gt;We say X&lt;sub&gt;1&lt;/sub&gt;, X&lt;sub&gt;2&lt;/sub&gt;, …, X&lt;sub&gt;n&lt;/sub&gt; are jointly continuous if
F&lt;sub&gt;X&lt;sub&gt;1&lt;/sub&gt;X&lt;sub&gt;2&lt;/sub&gt;…X&lt;sub&gt;n&lt;/sub&gt;&lt;/sub&gt;&lt;/sub&gt;(x&lt;sub&gt;1&lt;/sub&gt;x&lt;sub&gt;2&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) = P{X&lt;sub&gt;1&lt;/sub&gt;&amp;#x3C;=x&lt;sub&gt;1&lt;/sub&gt;, X&lt;sub&gt;2&lt;/sub&gt;&amp;#x3C;=x&lt;sub&gt;2&lt;/sub&gt;, … X&lt;sub&gt;n&lt;/sub&gt;&amp;#x3C;=x&lt;sub&gt;n&lt;/sub&gt;}&lt;/p&gt;
&lt;p&gt;= ∫∫ F&lt;sub&gt;X&lt;sub&gt;1&lt;/sub&gt;X&lt;sub&gt;2&lt;/sub&gt;…X&lt;sub&gt;n&lt;/sub&gt;&lt;/sub&gt;&lt;/sub&gt;(x&lt;sub&gt;1&lt;/sub&gt;x&lt;sub&gt;2&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;)du&lt;sub&gt;1&lt;/sub&gt;du&lt;sub&gt;2&lt;/sub&gt;…du&lt;sub&gt;n&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;Example:
Let a dart land uniformly at random on a 2d dartboard of radius r.
The joint density will be flat over the dartboard&lt;/p&gt;
&lt;p&gt;{1/pi*r&lt;sup&gt;2&lt;/sup&gt;, x&lt;sup&gt;2&lt;/sup&gt; + y&lt;sup&gt;2&lt;/sup&gt;}
Independence: Random Variables X,Y are independent if F&lt;sub&gt;xy&lt;/sub&gt;(x,y) = F&lt;sub&gt;x&lt;/sub&gt;(x) * F&lt;sub&gt;y&lt;/sub&gt;(x)
If X,Y are continuous and independent, their joint density is the product of the marginals&lt;/p&gt;
&lt;h3 id=&quot;expectation-of-continuous-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#expectation-of-continuous-random-variables&quot; aria-label=&quot;expectation of continuous random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Expectation of continuous random variables&lt;/h3&gt;
&lt;p&gt;Same as discrete case, replace sums with integrals
E[X] = ∫x f&lt;sub&gt;x&lt;/sub&gt;(x)dx&lt;/p&gt;
&lt;p&gt;More generally:
E[g(X&lt;sub&gt;1&lt;/sub&gt;…X&lt;sub&gt;n&lt;/sub&gt;)] = ∫…∫g(x&lt;sub&gt;1&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) f&lt;sub&gt;x&lt;sub&gt;1&lt;/sub&gt; … x&lt;sub&gt;n&lt;/sub&gt;&lt;/sub&gt;(x&lt;sub&gt;1&lt;/sub&gt; … x&lt;sub&gt;n&lt;/sub&gt;)dx&lt;sub&gt;1&lt;/sub&gt; … dx&lt;sub&gt;n&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;Example:
Var(X) = ∫(X-E[X])&lt;sup&gt;2&lt;/sup&gt; f&lt;sub&gt;x&lt;/sub&gt;(x)dx&lt;/p&gt;
&lt;p&gt;Example: X ~ Unif(a,b)
E[X] = ∫ uniform density function&lt;/p&gt;
&lt;p&gt;= ∫ x * 1 / (b-a) dx&lt;/p&gt;
&lt;p&gt;= 1/2 * (b&lt;sup&gt;2&lt;/sup&gt; - a&lt;sup&gt;2&lt;/sup&gt;) / (b-a)&lt;/p&gt;
&lt;p&gt;= 1/2 * (b+a)&lt;/p&gt;
&lt;p&gt;Example: Var(X) = E[X&lt;sup&gt;2&lt;/sup&gt;] - (E[X])&lt;sup&gt;2&lt;/sup&gt;
= 1/2 (b-a)&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Let r = sqrt(x&lt;sup&gt;2&lt;/sup&gt; + y&lt;sup&gt;2&lt;/sup&gt;)
Compute the probability that the dart is in the middle half of the dartboard.&lt;/p&gt;
&lt;p&gt;P{R&amp;#x3C;= r/2} = P{x&lt;sup&gt;2&lt;/sup&gt; + y&lt;sup&gt;2&lt;/sup&gt; &amp;#x3C;= r&lt;sup&gt;2&lt;/sup&gt; / 4}&lt;/p&gt;
&lt;p&gt;= E[{x&lt;sup&gt;2&lt;/sup&gt; + y&lt;sup&gt;2&lt;/sup&gt; &amp;#x3C;= r&lt;sup&gt;2&lt;/sup&gt; / 4}]&lt;/p&gt;
&lt;p&gt;= 1/(pi * r&lt;sup&gt;2&lt;/sup&gt;) ∫ {x&lt;sup&gt;2&lt;/sup&gt; + y&lt;sup&gt;2&lt;/sup&gt; &amp;#x3C;= r&lt;sup&gt;2&lt;/sup&gt; / 4} dx dy&lt;/p&gt;
&lt;h1 id=&quot;gaussian-distribution-derived-distributions-continuous-bayes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#gaussian-distribution-derived-distributions-continuous-bayes&quot; aria-label=&quot;gaussian distribution derived distributions continuous bayes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Gaussian Distribution, Derived Distributions, Continuous Bayes&lt;/h1&gt;
&lt;p&gt;Discrete: Expectations come from PMF and sums
Continuous: Expectations come from PDF and integrals&lt;/p&gt;
&lt;h3 id=&quot;examples-of-continuous-distributions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#examples-of-continuous-distributions&quot; aria-label=&quot;examples of continuous distributions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Examples of continuous distributions&lt;/h3&gt;
&lt;p&gt;Uniform(a,b)
Exp(N)
N(µ, σ&lt;sup&gt;2&lt;/sup&gt;)&lt;/p&gt;
&lt;h2 id=&quot;exponential-distribution&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#exponential-distribution&quot; aria-label=&quot;exponential distribution permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Exponential Distribution&lt;/h2&gt;
&lt;p&gt;Suppose we want to model a memoryless process. For example, as a switch sending packets, it doesn’t matter how long you wait for a packet to show up, the expected wait time for the next packet doesn’t change.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Mathematically&lt;/strong&gt;: Let X be a non-negative random variable with the memoryless property.
Memoryless = P{X&gt;t+s|X&gt;s} = P{X&gt;t} for all t,s &gt; 0
If I’ve waited for s seconds, the probability P{X&gt;t} is still unchanged&lt;/p&gt;
&lt;p&gt;P({X&gt;t+s} ∩ {x &gt; s}) = P({x &gt; t}) P({x &gt; s})
Get rid of {x &gt; s} since if x &gt; t + s, x must be greater than s&lt;/p&gt;
&lt;p&gt;F(t + s) = F(t) F(s)
The only unique solution to the functional equality that is a CDF(must be non-negative, monotone increasing) of the form F&lt;sub&gt;x&lt;/sub&gt; = e&lt;sup&gt;-λx&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;If x has memoryless property, F(X) = 1 - e&lt;sup&gt;-λt&lt;/sup&gt; for some λ &gt; 0&lt;/p&gt;
&lt;h2 id=&quot;gaussian-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#gaussian-random-variables&quot; aria-label=&quot;gaussian random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Gaussian Random Variables&lt;/h2&gt;
&lt;p&gt;The sum of independent effects. Height of NBA players, satisfaction of jobs, sum of voltage across resistor.&lt;/p&gt;
&lt;p&gt;We call N(0,1), the standard normal distribution. &lt;/p&gt;
&lt;p&gt;CDF:  1/2pi ∫exp(-µ/2)&lt;sup&gt;2&lt;/sup&gt;du&lt;/p&gt;
&lt;p&gt;P(X&amp;#x3C;= x) = P((x-µ)/σ &amp;#x3C;= (x-µ)/σ) = Φ((x-µ)/σ)
Gaussians have many nice properties&lt;/p&gt;
&lt;p&gt;If X is gaussian, then so is aX + b.
If X,Y are independent gaussians, then X+Y is gaussian&lt;/p&gt;
&lt;p&gt;Example: Let V ~ N(1, 5&lt;sup&gt;2&lt;/sup&gt;) be input voltage to chip, averaged over 1 second.
Our chip fails if voltage dips below 0.5 volts or exceeds 2.5 volts for any one second period&lt;/p&gt;
&lt;p&gt;Probabilty(chip fails in 60 second duration) &amp;#x3C;= 60 * Probability(chip fails in 1 second)
60 * Probability(chip fails in 1 second) =
= 60 * Probability(V &amp;#x3C; 0.5) + Probability(V &gt; 2.5)
= Φ((0.5 - 1)/σ)  + (1 - Φ((2.5-1)/σ))&lt;/p&gt;
&lt;p&gt;Example: cellphone sends a bit B ∈ {-1, 1} to tower. Tower receives Y = B + N, N ~ N(0,1). Tower makes decisions B(Y) = sign(Y)
P(err | B = 1) &lt;/p&gt;
&lt;p&gt;Given that I receive {Y=y} what is the probability that B = 1
P({B = 1}) = P(Y ∈ [y, y + 𝛿] | B = 1) P(1)&lt;/p&gt;
&lt;p&gt;= P&lt;sub&gt;B|Y&lt;/sub&gt;(1 | y) = P&lt;sub&gt;B&lt;/sub&gt;(1) * f&lt;sub&gt;Y|B&lt;/sub&gt;(y|1) / f&lt;sub&gt;y&lt;/sub&gt;(y)
This is bayes rule for one &lt;/p&gt;
&lt;p&gt;= (1/sqrt(2pi) * exp(-(y-1)&lt;sup&gt;2&lt;/sup&gt;/2)) / (1/2 * 1/sqrt(2pi) * exp(-(y+1)&lt;sup&gt;2&lt;/sup&gt;)/2) + …
= 1 / (1 + e&lt;sup&gt;-2y&lt;/sup&gt;)&lt;/p&gt;
&lt;p&gt;This is b
Example:
Last example motivates the definition of conditional density
If X,Y are jointly continuous, we define conditional density of X given Y:&lt;/p&gt;
&lt;p&gt;f&lt;sub&gt;x|y&lt;/sub&gt;(x|y) = f&lt;sub&gt;xy&lt;/sub&gt;(x,y) / f&lt;sub&gt;y&lt;/sub&gt;(y)
interpretation: is the density of X given I know {Y=y}&lt;/p&gt;
&lt;p&gt;Bayes rule
f&lt;sub&gt;x|y&lt;/sub&gt;(x|y) = f&lt;sub&gt;x&lt;/sub&gt;(x) / f&lt;sub&gt;y&lt;/sub&gt;(y) * f&lt;sub&gt;y|x&lt;/sub&gt;(y|x)&lt;/p&gt;
&lt;p&gt;Example:
For X,Y that are jointly continuous, we have
E[X|Y=y] = ∫ x f&lt;sub&gt;x|y&lt;/sub&gt;(x|y)dx
CE still satisfies tower property: E[g(y|x)] = E[g(y)E[X|Y]]&lt;/p&gt;
&lt;h2 id=&quot;derived-distributions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#derived-distributions&quot; aria-label=&quot;derived distributions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Derived Distributions&lt;/h2&gt;
&lt;p&gt;Distribution of X give by CDF F&lt;sub&gt;x&lt;/sub&gt;. Suppose we define &lt;code class=&quot;language-text&quot;&gt;Y = g(x)&lt;/code&gt; for some function g&lt;/p&gt;
&lt;p&gt;What is the distribution of Y?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Do you really need this distribution?&lt;/li&gt;
&lt;li&gt;If you really need the distribution, it is best to work with CDFs&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Example:
X continuous random variable, Y = aX + b
F&lt;sub&gt;y&lt;/sub&gt;(y) = P{aX &amp;#x3C;= y-b}
= P{x &amp;#x3C;= (y-b) / a if a &gt; 0, x &gt;= (y-b)/a if a &amp;#x3C; 0}
= {F&lt;sub&gt;x&lt;/sub&gt;((y-b)/a) if a &gt; 0, 1 - F&lt;sub&gt;x&lt;/sub&gt;((y-b)/a) if a &amp;#x3C; 0}&lt;/p&gt;
&lt;p&gt;f&lt;sub&gt;y&lt;/sub&gt;(y) = {1/a * F&lt;sub&gt;x&lt;/sub&gt;((y-b)/a) if a &gt; 0, -1/a * F&lt;sub&gt;x&lt;/sub&gt;((y-b)/a) if a &gt; 0}
= 1/|a| * f&lt;sub&gt;x&lt;/sub&gt;((y-b)/a)&lt;/p&gt;
&lt;p&gt;Y = AX + b
f&lt;sub&gt;y&lt;/sub&gt;(y) = 1/|det(A)|f&lt;sub&gt;x&lt;/sub&gt;(A&lt;sup&gt;-1&lt;/sup&gt;(y-b))&lt;/p&gt;
&lt;h1 id=&quot;information-theory-and-digital-communication-capacity-of-the-binary-erasure-channel-bec&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#information-theory-and-digital-communication-capacity-of-the-binary-erasure-channel-bec&quot; aria-label=&quot;information theory and digital communication capacity of the binary erasure channel bec permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Information Theory and Digital Communication, Capacity of the Binary Erasure Channel (BEC)&lt;/h1&gt;
&lt;h2 id=&quot;modes-of-convergence&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#modes-of-convergence&quot; aria-label=&quot;modes of convergence permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Modes of Convergence&lt;/h2&gt;
&lt;p&gt;Weak law of large numbers: Everyone in the room takes a coin and flips it 500 times. Then we can saw the empirical frequency is between .49 and .51. Then everyone flips it 500 more times. Then the empirical frequency is between .495 and .505. However, someone might have been between .49 and .51 in the first 500 but not .495 ad .505 in the first 1000
Strong law of large numbers: The empirical frequency will go to its true probability with probability 1.&lt;/p&gt;
&lt;p&gt;CLT is a statement about convergence in a distribution&lt;/p&gt;
&lt;h1 id=&quot;information-theory&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#information-theory&quot; aria-label=&quot;information theory permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Information Theory&lt;/h1&gt;
&lt;h2 id=&quot;source-coding-theorem&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#source-coding-theorem&quot; aria-label=&quot;source coding theorem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Source Coding Theorem&lt;/h2&gt;
&lt;h3 id=&quot;protocol&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#protocol&quot; aria-label=&quot;protocol permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Protocol&lt;/h3&gt;
&lt;p&gt;If I observe (x&lt;sub&gt;1&lt;/sub&gt;, …, x&lt;sub&gt;n&lt;/sub&gt;), then I describe it via bitstring (1, xxx…x) -&gt; log(A&lt;sub&gt;t/2&lt;/sub&gt;)
If I observe a sequence not in the typical set, I describe it brute force via bitstring&lt;/p&gt;
&lt;p&gt;What is the performance(average number of bits needed per symbol observed) for this scheme?
1/n * E[number of bits in representation] ≤ 1/n (2 + n(H(x)+E))P(x&lt;sub&gt;1&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) + 1/n (2 + nlog(x)) * P(x&lt;sub&gt;1&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) ≤ H(x) + E/2 + 4/n + log|x| * probability of sequence not being in typical set&lt;/p&gt;
&lt;h3 id=&quot;results&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#results&quot; aria-label=&quot;results permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Results&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Descriptions using ≤ H(x) + E bits per symbol on average exist&lt;/li&gt;
&lt;li&gt;Lossless descriptions using ≤ H(x) don’t exist&lt;/li&gt;
&lt;li&gt;Huffman encoding: If I know p&lt;sub&gt;x&lt;/sub&gt;, I can design a Huffman code requiring ≤ H(x) + 1/n bits on average to compress sequences of length n&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Question: How are we going to show we can compress down to the entropy?
Answer: Use concentration. For a sequence(X&lt;sub&gt;1&lt;/sub&gt;, x&lt;sub&gt;2&lt;/sub&gt;, …, x&lt;sub&gt;n&lt;/sub&gt;), let the probability of observing it be p(x&lt;sub&gt;1&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) = Π&lt;sub&gt;i=1&lt;/sub&gt;&lt;sup&gt;n&lt;/sup&gt; P&lt;sub&gt;x&lt;/sub&gt;(x&lt;sub&gt;i&lt;/sub&gt;)&lt;/p&gt;
&lt;p&gt;Theorem: Asymptotic Equipartition Property - If Xs are iid with respect to P&lt;sub&gt;x&lt;/sub&gt;, then -1/n log p(x&lt;sub&gt;1&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) converges to H(x) in probability&lt;/p&gt;
&lt;p&gt;Typical Set: For E &gt; 0, for each n ≤ 1 define typical set
A := { (x&lt;sub&gt;1&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) : p(x&lt;sub&gt;1&lt;/sub&gt;…x&lt;sub&gt;n&lt;/sub&gt;) &gt;= 2&lt;sup&gt;-n(H(x) + E)}&lt;/p&gt;
&lt;p&gt;Why is this called a typical set? It is a set of typical sequences.&lt;/p&gt;
&lt;p&gt;Question: Suppose I have N objects. What is the max number of bits I need to represent each object?
Answer: max of log(N) bits&lt;/p&gt;
&lt;h1 id=&quot;poisson-processes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#poisson-processes&quot; aria-label=&quot;poisson processes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Poisson Processes&lt;/h1&gt;
&lt;p&gt;Markov models: Map events that have memory
Poisson Processes: Random arrivals: customers coming into a store, beta particles detected by geiger counter, vehicles passing a tollbooth
Counting Processs: Starts at 0, right continuous, integer valued
Poison Process: a counting process with Exp(λ) interarrival times&lt;/p&gt;
&lt;p&gt;Thm: If N&lt;sub&gt;t&lt;/sub&gt; is a Poisson process with rate λ, then N&lt;sub&gt;t&lt;/sub&gt; ~ Poisson(λt)
P{N&lt;sub&gt;t&lt;/sub&gt; = n} = e&lt;sup&gt;-λt&lt;/sup&gt; * (λt)^n / n!&lt;/p&gt;
&lt;p&gt;Proof:
P{N&lt;sub&gt;t&lt;/sub&gt; = n} = P{T&lt;sub&gt;n&lt;/sub&gt; &amp;#x3C;= t &amp;#x3C; T&lt;sub&gt;n+1&lt;/sub&gt;}
= E[1&lt;sub&gt;{T&lt;sub&gt;n&lt;/sub&gt;} &amp;#x3C;= t&lt;/sub&gt; 1&lt;sub&gt;t &amp;#x3C; T&lt;sub&gt;n+1&lt;/sub&gt;&lt;/sub&gt;]&lt;/p&gt;
&lt;p&gt;Increments of Poisson process are stationary: N&lt;sub&gt;t+s&lt;/sub&gt; - N&lt;sub&gt;s&lt;/sub&gt; = N&lt;sub&gt;t + tau&lt;/sub&gt; - N&lt;sub&gt;tau&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;Poisson processes have independent increments:
if t&lt;sub&gt;0&lt;sub&gt; &amp;#x3C; t&lt;sub&gt;1&lt;sub&gt; &amp;#x3C; … &amp;#x3C; t&lt;sub&gt;k&lt;sub&gt;&lt;br&gt;
=&gt; increments N&lt;sub&gt;t1&lt;/sub&gt; - N&lt;sub&gt;t0&lt;/sub&gt;, N&lt;sub&gt;t2&lt;/sub&gt; - N&lt;sub&gt;t1&lt;/sub&gt;, … , N&lt;sub&gt;t1&lt;/sub&gt; - N&lt;sub&gt;t0&lt;/sub&gt; are independent&lt;/p&gt;
&lt;p&gt;Thm: If N&lt;sub&gt;t&lt;/sub&gt; is a counting process with independent stationary increments and N&lt;sub&gt;t&lt;/sub&gt; ~ Poisson(λt), then N&lt;sub&gt;t&lt;/sub&gt; ~ Poisson Process(λ)&lt;/p&gt;
&lt;p&gt;Conditional distribution of Arrivals
Thm: Conditioned on {N&lt;sub&gt;t&lt;/sub&gt; = n}, (T&lt;sub&gt;1&lt;/sub&gt;, T&lt;sub&gt;2&lt;/sub&gt;, …, T&lt;sub&gt;n&lt;/sub&gt;) = (Unif(1), … Unif(n))&lt;/p&gt;
&lt;p&gt;Example: Let cars pass through a tollbooth according to Poisson Process(λ).
Question: What is the probability that no cars pass in 2 minutes
P{N&lt;sub&gt;2&lt;/sub&gt; = 0} = (λ2)^0 * e^(-2λ) / 0! = e^(-2λ)&lt;/p&gt;
&lt;p&gt;Question: If 10 vehicles pass in 2 minutes, what is the distribution of vehicles that passed in the first 30 seconds?
Binomial(10, 1/4)&lt;/p&gt;
&lt;h2 id=&quot;mergingsuperposition-and-splittingthinning&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mergingsuperposition-and-splittingthinning&quot; aria-label=&quot;mergingsuperposition and splittingthinning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Merging(superposition) and Splitting(thinning)&lt;/h2&gt;
&lt;p&gt;Merging: If N&lt;sub&gt;1,t&lt;/sub&gt; is poisson process with rate λ and N&lt;sub&gt;2,t&lt;/sub&gt; is an independent poisson process with rate u, then N&lt;sub&gt;1,t&lt;/sub&gt; + N&lt;sub&gt;2,t&lt;/sub&gt; ~ PP(λ+u)&lt;/p&gt;
&lt;p&gt;Splitting: Independently mask arrival with 1.
Example: Let vehicles pass through a tollbooth with PP(λ). Let 1/3 of the vehicles be cards and 2/3s be trucks&lt;/p&gt;
&lt;p&gt;If 10 vehicles pass in the first 2 minutes, what is the distribution of cars that pass in the first 30 seconds?&lt;/p&gt;
&lt;h2 id=&quot;random-graphs-and-inference&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#random-graphs-and-inference&quot; aria-label=&quot;random graphs and inference permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Random Graphs and Inference&lt;/h2&gt;
&lt;p&gt;G ~ G(n,p): G is a graph with n verticies where each edge appears indepedently with probability p.&lt;/p&gt;
&lt;p&gt;Monotone Graph Properties have sharp thresholds: P {G ~ G(n,p) has property P} = {0 if p &amp;#x3C; threshold n , 1 if p &gt; threshold n}
There is some phase transition phenomena.&lt;/p&gt;
&lt;p&gt;Ex: p = {graph G has &gt;= 1 edge} Monotone property.
Claim: t(n) = 1/n^2
Proof: Let x = # of edges in G, p = c / n^2
What is the probability G has zero edges?
P{G has zero edges} = P{X=0} = (1-p)^(n C 2) = e^(-c/2)
This evaluates to basically 1 if c &amp;#x3C;&amp;#x3C; 1 and 0 if c &gt;&gt; 1&lt;/p&gt;
&lt;p&gt;Goal: For property p={graph G is connected}, show that t(n) = (log(n)/n)
If lambda &gt; 1, then P{G~G(n,p) is connected} -&gt; 1 as n-&gt;infinity
If lambda &amp;#x3C; 1, then P{G~G(n,p) is connected} -&gt; 0 as n-&gt;infinity&lt;/p&gt;
&lt;p&gt;Lemma: If X is a random variable, then P(X=0) &amp;#x3C;= Var(x)/(E[X])^2
Proof:
Var(x) = E[X-E[X]]^2
= P(X=0) * E[X-(E[X])^2 | X=0] + P(X!=0) * E[(X-E[X])^2 | X=0]
= P(X=0) * E[X]^2 + P(X!=0) * E[(X-E[X])^2 | X=0]&lt;/p&gt;
&lt;p&gt;Case lambda &amp;#x3C; 1:
Will show: P{G has isolated vertex} -&gt; 1
{G has isolated vertex} C {G is disconnected}
X = Σ I&lt;em&gt;i = # of isolated verticies, where I&lt;/em&gt;i = {0 if i not isolated, 1 if i isolated}
I&lt;em&gt;i ~ Bern(q) where q&lt;/em&gt;i := (1-p)^(n-1)
Var(X) = Σ Var(I&lt;em&gt;i) + Σ Covar(I&lt;/em&gt;i, I&lt;em&gt;j)
= nq(1-q) + n(n-1)Cov(I&lt;/em&gt;1, I_2)&lt;/p&gt;
&lt;p&gt;Where Cov(I&lt;em&gt;1, I&lt;/em&gt;2) = E[I&lt;em&gt;1I&lt;/em&gt;2] - (E[I])^2
P{G has no isolated vertices} = P{X=0} &amp;#x3C;= (nq(1-q) + n(n-1) * pnq^2/(1-p))/(n^2q^2)
&amp;#x3C;= (1-q)/nq + p/(1-p)
(1-q)/nq goes to zero since nq -&gt; infinity
p/(1-p) goes to zero as p -&gt; 0&lt;/p&gt;
&lt;p&gt;P{G disconnected} = P{U_k=1^{n/2} {There exists a set of k vertices separated from the rest of G}}
Apply union bound again
P{(n C k) P {vertices 1, …, }}&lt;/p&gt;
&lt;h3 id=&quot;inference&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#inference&quot; aria-label=&quot;inference permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Inference&lt;/h3&gt;
&lt;p&gt;Given data, how do I choose the model that generated the data
X is the state of nature, often parameter or hypothesis -&gt; P_{Y|X} -&gt; Y produces some observation(data)
X may or may not be the random variable
If it is, then the distribution of X is called a prior(Bayesian Inference)&lt;/p&gt;
&lt;h2 id=&quot;inference-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#inference-1&quot; aria-label=&quot;inference 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Inference&lt;/h2&gt;
&lt;p&gt;Goal: Infer X from Y
X -&gt; Model -&gt; Y&lt;/p&gt;
&lt;p&gt;Reasonable Approaches:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MLE(X|Y) = argmax P(Y|X)&lt;/li&gt;
&lt;li&gt;Binary Hypothesis testing. X(Y) = 1 if L(Y) &gt; lambda, 0 if L(Y) &amp;#x3C; lambda&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For any test X:Y, there are two fundamental error rates, false positives and false negatives&lt;/p&gt;
&lt;p&gt;False Positive: P{X(Y) = 1 | X = 0}&lt;/p&gt;
&lt;p&gt;False Negative: P{X(Y) = 0 | X = 1}&lt;/p&gt;
&lt;p&gt;Question: Given a constraint on type 1 error rate, how do we find the test that minimizes type II error rate?
Solution:
Solve X = argmin P{X(Y) = 0| X=1}
Answer: Randomized threshold tests are optimal: Neyman-Pearson Theorem
Given Beta, the optimal decision rule is X(Y) = 1 if L(Y) &gt; lambda, 0 if L(Y) &amp;#x3C; lambda, Bernoulli(gamma) if L(Y) = lambda
Where lambda and gamma are chosen such that P{X(Y) = 1 | X=0} = beta&lt;/p&gt;
&lt;p&gt;B = P(L(Y) &gt;= lambda | X=0)
= P(Y/sigma &gt;= 1/(2&lt;em&gt;sigma) + phi&lt;/em&gt;log(lambda|X=0))
= 1 - phi(1/(2&lt;em&gt;sigma) + sigma&lt;/em&gt;log(lambda))&lt;/p&gt;
&lt;p&gt;Question: Where does randomization enter the picture
Answer: Deterministic threshold tests define and lie on error curve, but don’t necessarily sweep the whole thing
Ex: If Y is discrete, say binary-valued, then L(Y) takes at most 2 values
Takes two tests and randomizes between them&lt;/p&gt;
&lt;p&gt;Threshold tests are optimal&lt;/p&gt;
&lt;p&gt;Estimation under mean squared error
Goal: Estimate X based on Y under some loss function
X -&gt; Model -&gt; Y&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Intro to Networking]]></title><description><![CDATA[Notes on Networking]]></description><link>https://albertsu.netlify.app//posts/private/networking</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/private/networking</guid><pubDate>Thu, 25 Aug 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h1 id=&quot;lecture-1---intro-to-the-internet-protocol-architecture&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lecture-1---intro-to-the-internet-protocol-architecture&quot; aria-label=&quot;lecture 1   intro to the internet protocol architecture permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lecture 1 - Intro to the internet, protocol, architecture&lt;/h1&gt;
&lt;p&gt;What is the internet?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Goal: transfer data between end hosts&lt;/li&gt;
&lt;li&gt;Infra: TCP, IP, DNS, etc.&lt;/li&gt;
&lt;li&gt;Applications: facebook, google, twitter. &amp;#x3C;- don’t give a shit about this in class&lt;/li&gt;
&lt;li&gt;End hosts: laptops, phones, pacemakers&lt;/li&gt;
&lt;li&gt;Switch: help end hosts communicate. ie router, phone on hotspot&lt;/li&gt;
&lt;li&gt;ISP: aws, at&amp;#x26;t, UC Berkeley&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;protocol-specification-of-messages-that-communicating-entities-exchangespecifications&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#protocol-specification-of-messages-that-communicating-entities-exchangespecifications&quot; aria-label=&quot;protocol specification of messages that communicating entities exchangespecifications permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Protocol: specification of messages that communicating entities exchangeSpecifications&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Useful for getting someone on board&lt;/li&gt;
&lt;li&gt;If you design the protocol poorly you will spend lots of time debugging&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;architecture&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#architecture&quot; aria-label=&quot;architecture permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Architecture&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Network vs the Internet- How do you interconnecy&lt;/li&gt;
&lt;li&gt;What ifno should googogle share via amazon&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;protocol-design-factors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#protocol-design-factors&quot; aria-label=&quot;protocol design factors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Protocol Design Factors&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Incentives for ISPs, topology, path selection, diagnostics, customers&lt;/li&gt;
&lt;li&gt;Enormous diversity and dynamic range with respect to parameters(packet loss, bandwidth, communication latency, types of endpoints, different users)&lt;/li&gt;
&lt;li&gt;How do you differentiate whe interoperability relies on a common protocol?&lt;/li&gt;
&lt;li&gt;Upgrading the internet not an option&lt;/li&gt;
&lt;li&gt;Speed of light =&gt; cannot go faster from berkeley to NY than 27.5 milliseconds&lt;/li&gt;
&lt;li&gt;Portions of the internet fail(software, switches, links, network interfaces)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-protocol-design-paradigm-for-the-internet&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-protocol-design-paradigm-for-the-internet&quot; aria-label=&quot;the protocol design paradigm for the internet permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The protocol design paradigm for the internet&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Decentralized control: Software defined networking(SDN), dsdn&lt;/li&gt;
&lt;li&gt;Best effort service model&lt;/li&gt;
&lt;li&gt;Route around trouble&lt;/li&gt;
&lt;li&gt;Dumb infra with smart endhosts: NFV: Richer in network services&lt;/li&gt;
&lt;li&gt;e2e design principle: edge computing&lt;/li&gt;
&lt;li&gt;layering&lt;/li&gt;
&lt;li&gt;federation via narrow waist interface&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How to prioritize goals?
What are the fundamental constraint?
How to decompose a problem?&lt;/p&gt;
&lt;h1 id=&quot;lecture-2---how-to-share-networking-resources&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lecture-2---how-to-share-networking-resources&quot; aria-label=&quot;lecture 2   how to share networking resources permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lecture 2 - How to share networking resources&lt;/h1&gt;
&lt;p&gt;Best Effort: Packet Switching, just send packets and hope for the best
Reservations: Circuit switching, end hosts reserve bandwidth when needed&lt;/p&gt;
&lt;h2 id=&quot;which-is-better-circuit-vs-packet-switching&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#which-is-better-circuit-vs-packet-switching&quot; aria-label=&quot;which is better circuit vs packet switching permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Which is better? Circuit vs Packet Switching?&lt;/h2&gt;
&lt;p&gt;Factors to consider:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Abstraction to applications&lt;/li&gt;
&lt;li&gt;Efficiency(at scale)&lt;/li&gt;
&lt;li&gt;Handling Failures(at scale)&lt;/li&gt;
&lt;li&gt;Complexity of implementation(at scale)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As an application developer, circuits offer better application performance due to reserved bandwidth and is more predictable and understandable. This is also very intuitive in support of business models(ie charge based on use). However, &lt;/p&gt;
&lt;h2 id=&quot;smooth-vs-bursty-applications&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#smooth-vs-bursty-applications&quot; aria-label=&quot;smooth vs bursty applications permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Smooth vs Bursty Applications&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Definition: Difference between peak and avg transmission rate&lt;/li&gt;
&lt;li&gt;Small speak to avg ratio(3:1) - ie voice&lt;/li&gt;
&lt;li&gt;Bursty ratio(100:1) - Ie Data applications, web browsing&lt;/li&gt;
&lt;li&gt;Phone network uses reservations, internet does not&lt;/li&gt;
&lt;li&gt;Circuit switching spends some time to setup/teardown circuits, inefficient when you don’t have much data to send&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;failures&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#failures&quot; aria-label=&quot;failures permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Failures&lt;/h2&gt;
&lt;h3 id=&quot;circuit-switching&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#circuit-switching&quot; aria-label=&quot;circuit switching permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Circuit Switching&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Network must do all the things needed for packet switching&lt;/li&gt;
&lt;li&gt;Endhosts must detect failure, teardown old reservations, send new reservation request&lt;/li&gt;
&lt;li&gt;All endhosts must do this&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;packet-switching&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#packet-switching&quot; aria-label=&quot;packet switching permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Packet Switching&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Link goes down, then what&lt;/li&gt;
&lt;li&gt;Network detects failures, recalculates routes&lt;/li&gt;
&lt;li&gt;Transient overload: When a point in time when you receive two packets at the same time&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;resource-reservation-protocol&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#resource-reservation-protocol&quot; aria-label=&quot;resource reservation protocol permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Resource Reservation Protocol&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Packet switching is the default&lt;/li&gt;
&lt;li&gt;Used to setup state&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can also buy a dedicated circuit: ie MPLS circuits, leased lines, &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Often used by enterprises from one branch location to another&lt;/li&gt;
&lt;li&gt;very expensive(10x higher than normal connection)&lt;/li&gt;
&lt;li&gt;statically set up, long lived, and per user(not per flow)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;circuit-vs-packet-switching-a-history&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#circuit-vs-packet-switching-a-history&quot; aria-label=&quot;circuit vs packet switching a history permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Circuit vs Packet Switching a History&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;1970s-80s used packet switching, well suited to bursty file transfer applications&lt;/li&gt;
&lt;li&gt;1980s-90s believed we’d need circuit switching. Envisioned that voice/live TV would be the Internet’s true killer app&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;life-of-a-packet&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#life-of-a-packet&quot; aria-label=&quot;life of a packet permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Life of a Packet&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Source has data to send to destination&lt;/li&gt;
&lt;li&gt;Chun it into packets: each packet has payload and header&lt;/li&gt;
&lt;li&gt;Packet travels along a link&lt;/li&gt;
&lt;li&gt;Arrives at a switch, switch forwards to next hop(or buffer or drop packet)&lt;/li&gt;
&lt;li&gt;Repeat last step until we reach destination or packet is dropped&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;designing-the-internet-top-down&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#designing-the-internet-top-down&quot; aria-label=&quot;designing the internet top down permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Designing the Internet Top Down&lt;/h2&gt;
&lt;h3 id=&quot;how-to-solve-a-problem&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-to-solve-a-problem&quot; aria-label=&quot;how to solve a problem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How to solve a problem?&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Define the problem&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Decompose the problem - Modularity(barbara liskov ted talk)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Decomposing system into smaller units, providing a separation of concerns&lt;/li&gt;
&lt;li&gt;Motivation: Musk wants to send bezos a hand written letter. The letter goes from Musk -&gt; aide -&gt; fedex -&gt; fedex -&gt; aide -&gt; Bezos. &lt;/li&gt;
&lt;li&gt;Each level understands the other people on their level&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Assign tasks to entities&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;internet-modularization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#internet-modularization&quot; aria-label=&quot;internet modularization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Internet Modularization&lt;/h3&gt;
&lt;p&gt;Lowest Layer of Abstraction &lt;br&gt;
Physical transfer of bits &lt;br&gt;
Best effort local packet delivery &lt;br&gt;
Best effort global packet delivery &lt;br&gt;
Reliable/Unreliable data delivery &amp;#x3C;- Layer where we care about packets &lt;br&gt;
Applications &lt;br&gt;
Highest Layer of abstraction&lt;/p&gt;
&lt;h3 id=&quot;local-vs-global-delivery&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#local-vs-global-delivery&quot; aria-label=&quot;local vs global delivery permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Local vs Global Delivery&lt;/h3&gt;
&lt;p&gt;Ethernet networks only speak to Ethernet networks
Optical Transport networks only speaks to optical networks.&lt;/p&gt;
&lt;h1 id=&quot;what-is-a-protocol&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-is-a-protocol&quot; aria-label=&quot;what is a protocol permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What is a Protocol?&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;An agreement between parties on how to communicate&lt;/li&gt;
&lt;li&gt;Defines syntax and semantics&lt;/li&gt;
&lt;li&gt;Exist at multiple layers  &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Each layer of the stack has multiple protocols except the network layer, which only has IP&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each layer depends on the layer below, supports the layer above, and is independent of the same layer protocols&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;why-layering&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-layering&quot; aria-label=&quot;why layering permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why Layering?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Innovation can proceed in parallel #OpenInnovation&lt;/li&gt;
&lt;li&gt;Different communities can innovate, ie L7(app devs) vs L1(chip designers)&lt;/li&gt;
&lt;li&gt;The end host must implement all layers&lt;/li&gt;
&lt;li&gt;The network must implement L1-L3, L4+ is for reliability and reliable data transport&lt;/li&gt;
&lt;li&gt;Applications think about data, nic/driver cares about packets, network stack translates between these two&lt;/li&gt;
&lt;li&gt;Ethernet doesn’t know how to talk to OTN, Ethernet goes to IP which sends it to OTN which sends it to other OTN which sends it to IP which sends it to Ethernet&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;layer-encapsulation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#layer-encapsulation&quot; aria-label=&quot;layer encapsulation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Layer Encapsulation&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Take data, add app Header(ie HTTP)&lt;/li&gt;
&lt;li&gt;Add transport header(ie port number)&lt;/li&gt;
&lt;li&gt;Add Network header(ie host address, ip)&lt;/li&gt;
&lt;li&gt;Add L2 header(ie ethernet address)&lt;/li&gt;
&lt;li&gt;Now your packet should be on wire and have a header from all layers!&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;architectural-wisdom&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#architectural-wisdom&quot; aria-label=&quot;architectural wisdom permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Architectural Wisdom&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;End to End arguments in system Design&lt;/li&gt;
&lt;li&gt;The Design Philosphy of the DARPA internet protocols&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;end-to-end-principle&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#end-to-end-principle&quot; aria-label=&quot;end to end principle permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;End to End Principle&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Guides the debate about what functionality the network does or doesn’t implement&lt;/li&gt;
&lt;li&gt;Should we implement reliability in the network?&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Solution 1: Implement reliability at each step(network must implement reliability)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Problem: Cannot be perfectly reliable. What happens if a component has a bug or fails between two steps.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Solution 2: End to end check and retry(does not assume network is reliable)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sometimes you want reliability in the network to increase performance&lt;/p&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions?&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;Difference between packet switching and circuit switching?&lt;/li&gt;
&lt;li&gt;How do we do reliable packet delivery?&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Borrowing Protocols]]></title><description><![CDATA[A deep dive into borrowing protocols]]></description><link>https://albertsu.netlify.app//posts/crypto/borrow</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/borrow</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;asset-price-movements-and-liquidations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#asset-price-movements-and-liquidations&quot; aria-label=&quot;asset price movements and liquidations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Asset Price Movements and Liquidations&lt;/h1&gt;
&lt;p&gt;Synthetic Asset protocols ie DAI, Mirror, Synthetix, Yeti&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Needs oracle that provides prices of collateral asset&lt;/li&gt;
&lt;li&gt;Can mint new DAI when &lt;code class=&quot;language-text&quot;&gt;O_t * a * c &gt;= b&lt;/code&gt; where O_t is the oracle price, a is the amount of collateral, c is the collateral factor(usually less than 1), b is the amount of synthetic tokens&lt;/li&gt;
&lt;li&gt;If the oracle updates and cause the above invariant not to hold, a liquidation of the position is allowed(This is very bad for the person who took out their position!!)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the multi-collateral case, O&lt;em&gt;t, a, c, b are all vectors and the following invariant is used
`sum over collaterals(O&lt;/em&gt;t * a * c) &gt;= b`&lt;/p&gt;
&lt;p&gt;If you have a mixture of two assets(ie 50% eth and 50% bitcoin), as long as the oracle prices are not perfectly correlated, there is a smaller chance that the collaterals move in a way to get you liquidated.&lt;/p&gt;
&lt;h3 id=&quot;arguments-for-not-doing-this&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#arguments-for-not-doing-this&quot; aria-label=&quot;arguments for not doing this permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Arguments for not doing this?&lt;/h3&gt;
&lt;p&gt;Might be hard to set the parameters for &lt;code class=&quot;language-text&quot;&gt;O_t, a, c, b&lt;/code&gt;, but gauntlet already does this for collateral ratios on compound and aave&lt;/p&gt;
&lt;h3 id=&quot;why-is-everything-correlated&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-is-everything-correlated&quot; aria-label=&quot;why is everything correlated permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why is everything correlated?&lt;/h3&gt;
&lt;p&gt;Things are empirically correlated and the why doesn’t really matter.&lt;/p&gt;
&lt;p&gt;People who invest in an asset class want to be diversified, if the bitcoin in their portfolio goes up, they want to rebalance to stay diversified so they sell part of their bitcoin and buy eth, causing the eth price to go up.&lt;/p&gt;
&lt;h1 id=&quot;risk-modeling-for-protocols-with-liquidations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#risk-modeling-for-protocols-with-liquidations&quot; aria-label=&quot;risk modeling for protocols with liquidations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Risk Modeling for Protocols with Liquidations&lt;/h1&gt;
&lt;h2 id=&quot;example&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#example&quot; aria-label=&quot;example permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Example&lt;/h2&gt;
&lt;p&gt;Max Loan Size
Supply vector x collateral ratio * prices
Asset | Collateral factor
ETH | .825
DAI | .825
WBTC | .7&lt;/p&gt;
&lt;h1 id=&quot;mechanics-of-liquidation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mechanics-of-liquidation&quot; aria-label=&quot;mechanics of liquidation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mechanics of Liquidation&lt;/h1&gt;
&lt;p&gt;When liquidation is allowed, liquidators repay the borrowed amount and gets a portion of the collateral + some bonus. THe liquidator immediately market dumps the collateral + bonus.&lt;/p&gt;
&lt;p&gt;There’s a routing library in Julia that Bain cap wrote(doesn’t support curve/univ3)&lt;/p&gt;
&lt;h2 id=&quot;cascading-liquidation-feedback-loop&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cascading-liquidation-feedback-loop&quot; aria-label=&quot;cascading liquidation feedback loop permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cascading Liquidation Feedback Loop&lt;/h2&gt;
&lt;p&gt;Liquidations -&gt; Market Dump -&gt; Price Drop -&gt; More Liquidation&lt;/p&gt;
&lt;p&gt;Algorithm:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Input current state of lending markets, exchanges, prices
While True:
Check for liquidations
If liquidations:
Route them over exchange graph, update exchange states, update prices to post dump prices&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Why?
Allows us to calculate structural component expected loss vector and variance covariance matrix based on actual state of the chain
Allows us to better understand price trajectories. Can sell to people who care&lt;/p&gt;
&lt;h3 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h3&gt;
&lt;p&gt;What’s the intuition behind multi-collateral synthetics being less likely to liquidate? What about non-stablecoins?&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Cosmos]]></title><description><![CDATA[A deep dive into cosmos]]></description><link>https://albertsu.netlify.app//posts/crypto/cosmos</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/cosmos</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;cosmos&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cosmos&quot; aria-label=&quot;cosmos permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cosmos&lt;/h2&gt;
&lt;p&gt;Most blockchains have:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Shared execution layer&lt;/li&gt;
&lt;li&gt;Smart contracts&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;what-do-i-mean-when-i-say-cosmos&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-do-i-mean-when-i-say-cosmos&quot; aria-label=&quot;what do i mean when i say cosmos permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What do I mean when I say Cosmos?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Not Cosmos Hub&lt;/li&gt;
&lt;li&gt;Not $ATOM&lt;/li&gt;
&lt;li&gt;Cosmos SDK: Tendermint Consensus + IBC Modules + other stuff&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;philosophy&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#philosophy&quot; aria-label=&quot;philosophy permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Philosophy&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Instead of shared execution layer, you want application specific chains.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Benefit 1: You have control&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Precompiles - code that denotes complicated computations cheaper on chain. If you don’t have a precompile, you need to use the evm. E.g. cryptography. Defined in clients Cacn technically use .com domain as ENS, but this is extremely expensive to do DNSSEC onchain since cryptography isn’t on chain. Might cost $1000 some money to verify&lt;/li&gt;
&lt;li&gt;Novel consensus/Protocol Design. Osmosis wants to prevent MEV from happening; they want to use threshold encryption to do so. Thus, Osmosis can embed this in their chain&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Benefit 2: Blockspace Monopoly&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vertical Scaling brings problems like state bloat, computation power. Solana drops Merkle trees from client design to improve L1 scaling.&lt;/li&gt;
&lt;li&gt;Cosmos Approach: Instead of scaling vertically, you can create your own blockchain and scale horizontally. If each application has their own separate throughput, Polygon doesn’t get rekt bc people are playing sunflower games.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ibc&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ibc&quot; aria-label=&quot;ibc permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;IBC&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;relies on instant finality&lt;/li&gt;
&lt;li&gt;TCP/IP - not a bridge&lt;/li&gt;
&lt;li&gt;easy to add Cosmos based blockchains and other blockchains with {easy way to create light client proofs, Relayer}&lt;/li&gt;
&lt;li&gt;peg zone&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Relayer&lt;/strong&gt;: trustless way to send data from one blockchain to another. Think of it as a cable that can transmit data from one chain to another. Security comes from the light client proof, relayers have no verification.
End Goal: Each wallet is its own relayer. Relayers also get transaction fees in the future. Currently, relayers are subsidized via the Interchain foundation(Ethereum foundation equivalent)&lt;/li&gt;
&lt;li&gt;No flash loans, flash mints, flash anything via IBC bc that requires atomicity.&lt;/li&gt;
&lt;li&gt;Can do token transfers, cross chain swaps&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/66d60f0716e433b21353b3ed744a166d/29114/IBCpic.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 29.583333333333332%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAIAAABM9SnKAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAlUlEQVQY03WPyRLDIAxD8/9fGsKSBspSCGnf4Jk2B6qD0RjLkpf3QO/9ui6IVCHnefaB1tq3f8ciT0ophPAcYLSUAokx5pyF1FrnYrbyJ8rjONjinEP2GmARq/86M7pt22MAsq6r915uEUyVP2ccEOBABKz2fafKzVT6JIdMxEyQVmstmY0xcKattRyChqZSilw07+IP4TFe5hIiFucAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/66d60f0716e433b21353b3ed744a166d/8ac56/IBCpic.webp 240w,
/static/66d60f0716e433b21353b3ed744a166d/d3be9/IBCpic.webp 480w,
/static/66d60f0716e433b21353b3ed744a166d/e46b2/IBCpic.webp 960w,
/static/66d60f0716e433b21353b3ed744a166d/f992d/IBCpic.webp 1440w,
/static/66d60f0716e433b21353b3ed744a166d/882b9/IBCpic.webp 1920w&quot;
              sizes=&quot;(max-width: 960px) 100vw, 960px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/66d60f0716e433b21353b3ed744a166d/8ff5a/IBCpic.png 240w,
/static/66d60f0716e433b21353b3ed744a166d/e85cb/IBCpic.png 480w,
/static/66d60f0716e433b21353b3ed744a166d/d9199/IBCpic.png 960w,
/static/66d60f0716e433b21353b3ed744a166d/07a9c/IBCpic.png 1440w,
/static/66d60f0716e433b21353b3ed744a166d/29114/IBCpic.png 1920w&quot;
            sizes=&quot;(max-width: 960px) 100vw, 960px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/66d60f0716e433b21353b3ed744a166d/d9199/IBCpic.png&quot;
            alt=&quot;IBCpic&quot;
            title=&quot;IBCpic&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;ibc-research&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ibc-research&quot; aria-label=&quot;ibc research permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;IBC Research&lt;/h2&gt;
&lt;p&gt;Quick notes&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bc of the blockchain trilemma{decentralization, scalability, security}, applications will use multiple blockchains to achieve the trilemma&lt;/li&gt;
&lt;li&gt;To communicate between blockchains&lt;/li&gt;
&lt;li&gt;Deploy contract on Ethereum: meant to communicate with validators&lt;/li&gt;
&lt;li&gt;Send package to validators&lt;/li&gt;
&lt;li&gt;Validators communicate with solana blockchain
Eg If transferring USDT, you lock USDT on ethereum contract and mint synthetic USDT on solana blockchain
&lt;strong&gt;Validator:&lt;/strong&gt; Who runs the validators between chains?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ibc-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ibc-1&quot; aria-label=&quot;ibc 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;IBC&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Handle Authentication, ordering data packets between blockchains, can use&lt;/li&gt;
&lt;li&gt;Recall above, the package needs to be validated&lt;/li&gt;
&lt;li&gt;Do you need to use IBC + a bridge?
Mental model: IBC is a validator. (Who runs the validator?)
Goal: Manage communication between two modules. This involves sending/receiving packets with establish connection&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-ibc-works&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-ibc-works&quot; aria-label=&quot;how ibc works permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How IBC works&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Properties of IBC: Data confidentiality + Legibility: Send as little data to validator as possible + validator needs to understand the data&lt;/li&gt;
&lt;li&gt;Reliability: Relayer + blockchain works independently, there is a chance of dropping packets. This is managed by a sequence number per packet.&lt;/li&gt;
&lt;li&gt;Flow Control: Depends on ledger, IBC does not have overriding rule&lt;/li&gt;
&lt;li&gt;Authentication: Whenever IBC is to be used, data must be first on the originating blockchain. - IBC handler(validator?) verifies the data&lt;/li&gt;
&lt;li&gt;Statefulness: Three parts - clients, connection, channel&lt;/li&gt;
&lt;li&gt;Clients: info about state of both blockchains
connection: identifiers/data structures agreed by both blockchains&lt;/li&gt;
&lt;li&gt;Channel: info about encoding info, state, sequence numbers&lt;/li&gt;
&lt;li&gt;Multiplexing: smart contracts can use single IBC connection. Generally one to one but IBC supports one to many and many to one&lt;/li&gt;
&lt;li&gt;Relayer - keeps watch of state chain from origin chain(ie Ethereum in example above)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;use-case&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#use-case&quot; aria-label=&quot;use case permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Use Case&lt;/h2&gt;
&lt;p&gt;Why switch networks when purchasing insurance on other chain?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If vault and pool are connected with IBC, user can buy insurance from any chain while spending from mainnet wallet.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions?&lt;/h2&gt;
&lt;p&gt;Confirmation time is 15 seconds on ETH, Bitcoin is 10 minutes, can we still use IBC?
Need to wait 10 minutes?&lt;/p&gt;
&lt;p&gt;What about reorgs? There’s never true finality on proof of work chains right?
Solved via validators?&lt;/p&gt;
&lt;p&gt;Learning - Learn more about cosmos
Document - Publish technical articles, explainer articles, based on learning
Buidling - play with cosmos ibc, a bit tough scotty doesn’t believe in us :(, Spinning up dapp chain, running a relayer&lt;/p&gt;
&lt;h1 id=&quot;questions-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions-1&quot; aria-label=&quot;questions 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;
&lt;h2 id=&quot;subnets-vs-cosmos&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#subnets-vs-cosmos&quot; aria-label=&quot;subnets vs cosmos permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Subnets vs Cosmos&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;There is an expectation that you share security with Avalanche. Problem is that shared security isn’t free, you need to pay avalanche validators for this.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Tendermint is novel: instant finality + 2/3 network validators needs to be aligned. Instant finality is huge because it simplifies multichain consensus. In a proof of work blockchain, by the virtue of a 51% attack, blocks are not final since you can end up with uncle blocks&lt;a href=&quot;https://medium.com/dragonfly-research/dr-reorg-or-how-i-learned-to-stop-worrying-and-love-mev-2ee72b428d1d&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;reorgs&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This is bad for bridges because a transaction where you burn a token to mint it via a bridge to a different chain can be reverted due to a reorg.&lt;/li&gt;
&lt;li&gt;bridge UX gets killed&lt;/li&gt;
&lt;li&gt;Multihop dexes can take a very long time because you need to wait for probabilistic finality.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Are there Oracles natively in Cosmos?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No current oracles, but can built oracle chain &amp;#x3C;— big brain project right here&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Fixed Yield]]></title><description><![CDATA[Notes on ideas and protocols building fixed yields in DeFi]]></description><link>https://albertsu.netlify.app//posts/crypto/fixedyield</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/fixedyield</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;fixed-yield-notes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fixed-yield-notes&quot; aria-label=&quot;fixed yield notes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fixed Yield Notes&lt;/h1&gt;
&lt;p&gt;Zero coupon bond: Worth 1 dollar at some point in the future. It is called a zero coupon bonds because there is no discount, you can see the fixed income rate by looking at how many zero coupon bonds you can buy.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you can buy 102 zero coupon bonds that are redeemable in one year for 100 dollars, your risk free rate after 1 year is 2%
Equivalent to zero coupon bond&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;why-fixed-income&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-fixed-income&quot; aria-label=&quot;why fixed income permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why Fixed Income?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Variable yields means uncertainty with to what your portfolio value will be in the future&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Fixed income is powerful when applied over multiple rates over a long time period. The randomness of the rates leads to a log normal distribution with a Fat tail, and nothing in this fat right tail can be used by institution.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ie pension fund only needs to pay back pensions, the long tail is not useful if they have already achieved the returns. Thus, I can sell this long tail and get some more guarenteed returns&lt;/li&gt;
&lt;li&gt;Look into central limit theorem for how the distribution is generated&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;end-users&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#end-users&quot; aria-label=&quot;end users permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;End Users&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Institutions, people who want higher expected yields&lt;/li&gt;
&lt;li&gt;Institutions observe the price of the zero coupon bond&lt;/li&gt;
&lt;li&gt;Financial engineering to get yield + principal tokens(see element finance)&lt;/li&gt;
&lt;li&gt;Institutions buy the zero coupon bond at a certain price. They wait 1 year or however long then redeem it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There must be some people who are willing to take on additional risk to get higher expected returns
Will likely be complete overlap between fixed income product and people that buy protection&lt;/p&gt;
&lt;h2 id=&quot;how-does-the-product-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-does-the-product-work&quot; aria-label=&quot;how does the product work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How does the product work?&lt;/h2&gt;
&lt;p&gt;Take yield bearing token aUST(anchor UST) and split it into paUST(Fixed Yield) and yaUST(Random yield).
The paUST is always worth 1 dollar at expiration. The yaUST’s value depends on what the Anchor yields look like between creation and expiration. Higher anchor yields = higher yaUST value&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Users can deposit UST&lt;/li&gt;
&lt;li&gt;Get aUST&lt;/li&gt;
&lt;li&gt;Deposit aUST into fixed income vault&lt;/li&gt;
&lt;li&gt;Protocol splits aUST into paUST(redeems to 1 UST at expiration) and yaUST(variable yield at expiration)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you want to get fixed income, sell your yaUST and buy paUST in a DEX
If you want higher expected yields, sell your paUST and buy yaUST in a DEX&lt;/p&gt;
&lt;h1 id=&quot;fixed-income-amms&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fixed-income-amms&quot; aria-label=&quot;fixed income amms permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fixed Income AMMs&lt;/h1&gt;
&lt;p&gt;How do we design an AMM for a fixed yield product?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As the maturity approaches, the principal get closer and closer to a dollar since when it matures, you can redeem it for a dollar.&lt;/li&gt;
&lt;li&gt;Interest rates tend to be more stable than asset prices, thus the curve should be flatter than &lt;code class=&quot;language-text&quot;&gt;x * y = k&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;yield-space-amm&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#yield-space-amm&quot; aria-label=&quot;yield space amm permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Yield space AMM&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;x^(1-t)+y^(1-t)=k&lt;/code&gt;
Can chop off half of reserves since zero coupon bonds are always cheaper&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;can shift the decay rate to non-linear decay rate&lt;/li&gt;
&lt;li&gt;if there are multiple competing zero coupon bonds(same asset but different)&lt;/li&gt;
&lt;li&gt;zero coupon bond on dai, zero coupon bond on usdc, zero coupon bond on usdt deposited into stableswap AMM, then take the LP token and put that into our &lt;code class=&quot;language-text&quot;&gt;x^(1-t)+y^(1-t)=k&lt;/code&gt; AMM&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For multiple maturities, you can create a nested AMM structure to trade between 3 month, 6 month, and 9 month maturities&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;create a 3 month, UST Pool, then take the {3 month, UST} LP token and pair it with the 6 month principal token {6 month, {3 month, UST}}, then take the {6 month, {3 month, UST}} LP token and pair it with the 9 month principal token to create a 3 layer nested AMM {9 month, {6 month, {3 month, UST}}}&lt;/li&gt;
&lt;li&gt;Wouldn’t this have less liquidity for later expiries?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions?&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;How do we solve the fungibility problem?
Treat them as different assets and add a market maker between them. As time to maturity approaches, the market maker should shift from a constant product market maker(x * y = k) to a stableswap (x^3 + y^3 = k)
Can also do nested AMMs&lt;/li&gt;
&lt;li&gt;If I buy now and the expiration period is 6 months from now and my friend buys tomorrow and the expiration period is 6 months from tomorrow, how do we manage the UX?
All 6 month fixed yields expire on the same day&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Mirror Protocol]]></title><description><![CDATA[A quick primer on Mirror Protocol from Terra Classic]]></description><link>https://albertsu.netlify.app//posts/crypto/mirror</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/mirror</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;mirror&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mirror&quot; aria-label=&quot;mirror permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mirror&lt;/h2&gt;
&lt;p&gt;Overcollateralized synthetic asset
Deposit bluna, luna, ust
Mint some index(ie price of oil, mTesla)&lt;/p&gt;
&lt;h2 id=&quot;mirror-risks&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mirror-risks&quot; aria-label=&quot;mirror risks permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mirror Risks&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Governance Risk&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create formal governance proposal, hide sus code in it, hope it passes before people realize(Same think that rekt beanstalk finance)&lt;/li&gt;
&lt;li&gt;Mirror v2 has a system of incentives to achieve quorum&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Oracle Risks&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;S&amp;#x26;P 500 oracle gave incorrect price and a large position was liquidated(250-500k)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Structural/Economic Risk&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;geometric-brownian-motion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#geometric-brownian-motion&quot; aria-label=&quot;geometric brownian motion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Geometric Brownian Motion&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Problem: continuous in time but users don’t act continuous in time but rather per block. The agent can continue to add more collateral as the price moves down to prevent liquidations.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;jump-process&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#jump-process&quot; aria-label=&quot;jump process permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Jump Process&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Poisson point process: gives the arrival of the jumps&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The model of the arrival in each independent event. The probability that a certain event arrives within a given interval is poisson distributed. Modeled by probability mass distribution, lambda tells you how often the jump happens on average.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Jumps: the prices at each jump&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;model&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#model&quot; aria-label=&quot;model permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Model&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Trader mints mS&amp;#x26;P by supplying bLUNA as collateral, they are required to supply at least
&lt;code class=&quot;language-text&quot;&gt;collateral amount &gt;= collateral factor* mint AMount * collateral price / synthetic price&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If no jumps occur in interval, no risk of liquidation because no price changes&lt;/li&gt;
&lt;li&gt;If one jump occurs, check if the jump was less than threshold.&lt;/li&gt;
&lt;li&gt;If two jumps occur, check if the first jump was less than threshold.&lt;/li&gt;
&lt;li&gt;If n jumps occur, need to check if any jump was less than threshold&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h2&gt;
&lt;p&gt;1.How does risk harbor provide protection against Mirror Liquidations?&lt;/p&gt;</content:encoded></item><item><title><![CDATA[MEV]]></title><description><![CDATA[Quick primer on MEV]]></description><link>https://albertsu.netlify.app//posts/crypto/borrow</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/borrow</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;p&gt;Broke: MEV is consensus mechanism that is the source of issues
Woke: Problem is from application layer, this is similar to the issues in the HFT space.&lt;/p&gt;
&lt;p&gt;People try to randomize arrival of orders, make fees, etc.
There was a good paper that prompted people to use batch auctions instead of central limit order books
CLOB: orders come in serial time, processed serially in order of arrival. This is the same as the transactions ordering in ethereum, whoever comes in first gets executed first.
Batch Auction: Instead of processing everything in continuous time one by one, wait and batch transactions and process them together. - For all transaction that came in this block, store them and execute them next block&lt;/p&gt;
&lt;p&gt;To submit an order on a dex, you submit an order and a slippage tolerance. If the slippage tolerance is too lenient, you can get front run for up to the slippage tolerance.&lt;/p&gt;
&lt;p&gt;This leads to people looking elsewhere for execution markets, ie flashbots. Since flashbots only has a certain percent of mining power, your order will execute slower than if you put your transaction in the standard pool.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Bob wants to buy 100 ETH. Order size +100 ETH&lt;/li&gt;
&lt;li&gt;Joe wants to sell 100 ETH. Order size 0 ETH&lt;/li&gt;
&lt;li&gt;Smitty wants to buy 10 ETH. Order size +10 ETH
The batch order of buy 10 ETH would then be submitted&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;overview-of-mev&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#overview-of-mev&quot; aria-label=&quot;overview of mev permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Overview of MEV&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Frontrunning&lt;/li&gt;
&lt;li&gt;arbitrage&lt;/li&gt;
&lt;li&gt;Liquidations&lt;/li&gt;
&lt;li&gt;Generalized Frontrunning: replacing profitable tx with&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;liquidations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#liquidations&quot; aria-label=&quot;liquidations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Liquidations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Whoever gets the liquidation first gets the money&lt;/li&gt;
&lt;li&gt;Liquidate position, market dump tokens&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Options]]></title><description><![CDATA[A quick primer on options]]></description><link>https://albertsu.netlify.app//posts/crypto/options</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/options</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;options&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#options&quot; aria-label=&quot;options permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Options&lt;/h2&gt;
&lt;p&gt;Why do we need a characteristic function and how does it relate to Options?
Options + probability are deeply related. If you know characteristic function of the option, you can compute the option price.&lt;/p&gt;
&lt;p&gt;Benefit of characteristic functions: Allows for more flexibility in pricing risk, volatility. Increases flexibility with regards to pricing.
“Correlation structure is easier to work with in characteristic function” - Prof Resnick&lt;/p&gt;
&lt;h2 id=&quot;characteristic-function&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#characteristic-function&quot; aria-label=&quot;characteristic function permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Characteristic function&lt;/h2&gt;
&lt;p&gt;Motivation: This stuff can be calculated on chain using Fast Fourier Transform if we have a characteristic function
Characteristic function: Alternative way to express info about random variable&lt;/p&gt;
&lt;p&gt;Recall cumulative density function (Probability that random variable is less than a given value)
E[e^(itX)] - corresponds to the fourier transform, which is a good way to model things&lt;/p&gt;
&lt;p&gt;Can express characteristic function as sum of the moments? E[X^n] term ~ price of a power future with power n.
The price of a power perpetual implies something? &amp;#x3C;- not sure what it implies&lt;/p&gt;
&lt;p&gt;Sum of two random variables =&gt; product of characteristic functions
^ What’s the use case here?&lt;/p&gt;
&lt;p&gt;Delta is useful for market makers - If we can compute delta easily, we can check things on chain?
^Spoiler alert, we can using fast fourier transform&lt;/p&gt;
&lt;p&gt;Two sides: uninformed flow + market makers on options(PhD physicist/math/stats)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If you are little boi and make options flow and sell via black scholes, jump is gonna rek you with diffusive, lattice, monte carlo bullshit.&lt;/li&gt;
&lt;li&gt;When you price something wrong, they can arb you immediately and this is hard to fix since you wrote this in a smart contract&lt;/li&gt;
&lt;li&gt;This makes on chain options difficulty&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What will be computed on chain and what will be computed offchain?
We should implement characteristic function as simpler function on chain using fft(divide and conquer algo- O(nlog(n))&lt;/li&gt;
&lt;li&gt;What is N in O(N log(N))?
Can be tuned, higher it is better the approximation, similar to resolution.&lt;/li&gt;
&lt;li&gt;What is an FFT?
&lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.youtube.com/watch?v=spUNpyF58BY&lt;/a&gt;
Thanks matt :D&lt;/li&gt;
&lt;li&gt;What other protocols have power futures?
Squeeth, Tracer, &lt;a href=&quot;https://zeta.markets/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://zeta.markets/&lt;/a&gt;. The later two aren’t really power futures though, they are just multipliers right?&lt;/li&gt;
&lt;li&gt;Are these markets priced by spot? Do they reflect alpha in spot?
Squeeth is underfunded, so people buy squeeth to hedge volatility future. Selling squeeth gives you positive EV, not enough liquidity in market for other side. No one wants to sell volatility. If there was a liquid options market, then you can hedge squeeth. In theory you can buy options and sell squeeth, and volatility, skewness hedged and set as options market maker.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;quanto-derivatives&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#quanto-derivatives&quot; aria-label=&quot;quanto derivatives permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Quanto Derivatives&lt;/h2&gt;
&lt;p&gt;Derivative that is settled in a different reference currency.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Anchor protection settled in usdc vs anchor protection settled in ust
Why do the premiums cost a different amount.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Why isn’t there another instrument that could close the gap in premiums between these products?
You are paying for more protection&lt;/p&gt;
&lt;p&gt;When the euro collapsed, greece, italy, spain defaulted. Two types of cds, one denominated in euros and one denominated in usd. The usd premiums are much more expensive than the cds premiums denominated in euros because if greece defaulted on their loans, the euro is more likely to collapse as well&lt;/p&gt;
&lt;p&gt;Effect of lower price of euros&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Oracles]]></title><description><![CDATA[Notes on the implementations and real world examples of oracles]]></description><link>https://albertsu.netlify.app//posts/crypto/Oracles</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/Oracles</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h1&gt;
&lt;p&gt;From the previous stablecoins post, Ampleforth’s AMPL is one example of a stablecoin that requires an oracle to properly function. Another example is flight insurance, how does the blockchain know when a flight has been delayed? Some other DeFi applications that need data include sports betting, wrapping other cryptocurrencies(bitcoin), synthetic assets(stocks), and undercollateralized lending.&lt;/p&gt;
&lt;p&gt;The blockchain does not have a connection to the internet: How do we get external data to contracts?&lt;/p&gt;
&lt;h1 id=&quot;building-an-oracle&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#building-an-oracle&quot; aria-label=&quot;building an oracle permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Building an Oracle&lt;/h1&gt;
&lt;h2 id=&quot;basic-oracle-design&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#basic-oracle-design&quot; aria-label=&quot;basic oracle design permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Basic Oracle Design&lt;/h2&gt;
&lt;p&gt;Build an oracle into the consensus protocol. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;What if the miner lies or cheats?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use multiple miners and use the data of a randomly selected miner.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What if the sending node lies or cheats?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use digital signatures and take the majority answer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What if the sending node goes down?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Allow for backup transmission.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What if the web site with data goes down?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use multiple websites.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This results in a decentralized oracle with good liveness, what if there are malicious attackers in the system?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;What if nodes disagree?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Take the majority value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What if nodes report different numerical values?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use the median. Given a minority of bad values, a median is an honest value or bounded by honest values.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;remaining-problems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#remaining-problems&quot; aria-label=&quot;remaining problems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Remaining Problems&lt;/h3&gt;
&lt;p&gt;These problems are usually solved at the protocol level, so solutions will differ based on the specific implementation.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;How do we ensure that a majority of nodes are honest?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How do we ensure nodes get paid for their service?&lt;/li&gt;
&lt;li&gt;How do we ensure that oracle reports are mined by miners in a timely way?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;implementations-of-oracles&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#implementations-of-oracles&quot; aria-label=&quot;implementations of oracles permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Implementations of Oracles&lt;/h1&gt;
&lt;h2 id=&quot;decentralized-exchanges-dexes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#decentralized-exchanges-dexes&quot; aria-label=&quot;decentralized exchanges dexes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Decentralized Exchanges (DEXes)&lt;/h2&gt;
&lt;p&gt;Decentralized Exchanges enable on chain trading of various asset pairs. As a result, the exchanges have the current valuation of the asset price, since mispricing the asset would result in an arbitrage opportunity. Thus, we can use the decentralized exchange price as the oracle price!&lt;/p&gt;
&lt;p&gt;Pros: Instant response and composable with other contracts! Also, there is an economic assurance that the oracle is correct.
Cons: Only price information can be returned and the oracle can be manipulated.&lt;/p&gt;
&lt;h3 id=&quot;decentralized-exchange-price-attack&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#decentralized-exchange-price-attack&quot; aria-label=&quot;decentralized exchange price attack permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Decentralized Exchange Price Attack&lt;/h3&gt;
&lt;p&gt;Situation: bZx, a lending protocol, used the Kyber exchange as a price oracle. Their ETH loans were backed with sUSD collateral based on Kyber price.
Attack:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The attacker sold ETH for sUSD on Kyber to drive down the ETH/sUSD price&lt;/li&gt;
&lt;li&gt;The attacker borrowed ETH for sUSD cheaply on bZx since the oracle reported that ETH is worth a lot less sUSD than it once was.&lt;/li&gt;
&lt;li&gt;The attacker ran away with the loaned eth, making 2381 ETH(673k USD)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Countermeasure: Use time weighted average oracles(TWAP) so attackers can’t drive down the price for any significant periods of time.&lt;/p&gt;
&lt;h1 id=&quot;verifiable-random-functions-vrfs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#verifiable-random-functions-vrfs&quot; aria-label=&quot;verifiable random functions vrfs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Verifiable Random Functions (VRFs)&lt;/h1&gt;
&lt;p&gt;Problem: Since everything is public on the blockchain and we can’t introduce any external data without an oracle, there is no randomness since we could simulate what will happen on chain by reading the mempool and running the transactions on a local node.&lt;/p&gt;
&lt;p&gt;Idea: The oracle uses a secret key to generate randomness. The randomness is verifiable and unpredictable.&lt;/p&gt;
&lt;h1 id=&quot;oracle-privacy&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#oracle-privacy&quot; aria-label=&quot;oracle privacy permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Oracle Privacy&lt;/h1&gt;
&lt;p&gt;Problem: Alice wants to buy flight insurance for her trip from San Francisco to New York, but how can she do that without everyone knowing that she’s flying from San Francisco to New York?&lt;/p&gt;
&lt;p&gt;Partial Solution: Use a trusted execution environment. This ensures integrity, as no one, not even the owner of the computer with the trusted execution environment can tamper with an application executing in it. This also ensures confidentiality, as no one, not even the owner of the computer with the trusted execution environment can learn about the data running in the environment. &lt;/p&gt;
&lt;p&gt;Problem: Hardware based trusted execution environments have serious vulnerabilities. ie Intel SGX
Solution: Use a DECO, a trusted execution environment alternative built using cryptographic techniques!&lt;/p&gt;
&lt;h1 id=&quot;remaining-questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#remaining-questions&quot; aria-label=&quot;remaining questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Remaining Questions&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;Why do we first learn about the mean in school then the median? Or at least this is what I learned in elementary school.&lt;/li&gt;
&lt;li&gt;How does a DECO work?&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[An EVM developer's guide to Solana]]></title><description><![CDATA[A quick primer on solana for someone who has developed on EVM chains]]></description><link>https://albertsu.netlify.app//posts/crypto/borrow</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/borrow</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;solana&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#solana&quot; aria-label=&quot;solana permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Solana&lt;/h1&gt;
&lt;p&gt;What are the differences between EVM and solana&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Bitcoin is based on UTXO, Ethereum uses the accounts model&lt;/li&gt;
&lt;li&gt;Solana also uses the accounts model&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;evm-accounts-vs-solana&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#evm-accounts-vs-solana&quot; aria-label=&quot;evm accounts vs solana permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;EVM accounts vs Solana&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Ethereum/EVM uses Externally Owned Accounts + Smart contract&lt;/li&gt;
&lt;li&gt;nonce, balance, codehash, storage root(256 bit hash of root node of merkle tree that encodes storage)&lt;/li&gt;
&lt;li&gt;Solana only has 1 type of account
Subtypes are data accounts and program accounts&lt;/li&gt;
&lt;li&gt;Lamports = wei&lt;/li&gt;
&lt;li&gt;owner = program owner, default is owned by system&lt;/li&gt;
&lt;li&gt;executable = whether this account can process instructions(true = program account, false = data account)&lt;/li&gt;
&lt;li&gt;data = raw data byte array stored by account&lt;/li&gt;
&lt;li&gt;rent_epoch = Next epoch that this account will owe rent(If you run out of rent, the account gets purged)
Program accounts only store logic in &lt;code class=&quot;language-text&quot;&gt;data&lt;/code&gt;, not state - which is stored in a separate account owned by this account&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;special-type-of-accounts-in-solana-pdas&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#special-type-of-accounts-in-solana-pdas&quot; aria-label=&quot;special type of accounts in solana pdas permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Special type of accounts in Solana: PDAs&lt;/h3&gt;
&lt;p&gt;A smart contract in solana needs to store state outside of program, they don’t want to store this using the same ed2559 elliptic curve to avoid collisions and someone getting the private key to this program in the future, so it uses a separate curve&lt;/p&gt;
&lt;h2 id=&quot;transactions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transactions&quot; aria-label=&quot;transactions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transactions&lt;/h2&gt;
&lt;p&gt;EVM has two types of transactions, sending ether vs calling smart contract&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;can only call single function&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Solana allows you to call multiple instructions in the same program
Need to pass all accounts that would be part of the transactions&lt;/p&gt;
&lt;h2 id=&quot;example-how-tokens-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#example-how-tokens-work&quot; aria-label=&quot;example how tokens work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Example: how tokens work&lt;/h2&gt;
&lt;h3 id=&quot;ethereum&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ethereum&quot; aria-label=&quot;ethereum permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Ethereum&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;I have 10 USDC, in the USDC contract, the mapping called _balances&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;mapping(address =&gt; uint256) private _balances&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;_balances[my address] = 10&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;solana-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#solana-1&quot; aria-label=&quot;solana 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Solana&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Because the state of a program is just some logic, every token can reuse the same token program logic&lt;/li&gt;
&lt;li&gt;image.png&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Random Solidity Notes]]></title><description><![CDATA[Things I didn't know]]></description><link>https://albertsu.netlify.app//posts/crypto/solidity-notes</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/solidity-notes</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;solidity-101-notes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#solidity-101-notes&quot; aria-label=&quot;solidity 101 notes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;a href=&quot;https://secureum.substack.com/p/solidity-101&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Solidity 101 Notes&lt;/a&gt;&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;A ‘^’ symbol prefixed to x.y.z in the pragma indicates that the source file may be compiled only from versions starting with x.y.z until x.(y+1).z. For e.g., “pragma solidity ^0.8.3;” indicates that source file may be compiled with compiler version starting from 0.8.3 until any 0.8.z but not 0.9.z. This is known as a “floating pragma.”&lt;/li&gt;
&lt;li&gt;NatSpec Comments: NatSpec stands for “Ethereum Natural Language Specification Format.” These are written with a triple slash (///) or a double asterisk block(/** … */) directly above function declarations or statements to generate documentation in JSON format for developers and end-users. It is recommended that Solidity contracts are fully annotated using NatSpec for all public interfaces (everything in the ABI). These comments contain different types of tags:&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;@title: A title that should describe the contract/interface&lt;/p&gt;
&lt;p&gt;@author: The name of the author (for contract, interface)&lt;/p&gt;
&lt;p&gt;@notice: Explain to an end user what this does (for contract, interface, function, public state variable, event)&lt;/p&gt;
&lt;p&gt;@dev: Explain to a developer any extra details (for contract, interface, function, state variable, event)&lt;/p&gt;
&lt;p&gt;@param: Documents a parameter (just like in doxygen) and must be followed by parameter name (for function, event)&lt;/p&gt;
&lt;p&gt;@return: Documents the return variables of a contract’s function (function, public state variable)&lt;/p&gt;
&lt;p&gt;@inheritdoc: Copies all missing tags from the base function and must be followed by the contract name (for function, public state variable)&lt;/p&gt;
&lt;p&gt;@custom…: Custom tag, semantics is application-defined (for everywhere)&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Stablecoins]]></title><description><![CDATA[Notes on the implementations and real world examples of stablecoins]]></description><link>https://albertsu.netlify.app//posts/crypto/stablecoins</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/stablecoins</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;variables-to-account-for-in-defistablecoins&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#variables-to-account-for-in-defistablecoins&quot; aria-label=&quot;variables to account for in defistablecoins permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Variables to account for in DeFi/Stablecoins&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Interest Rates in CeFi and DeFi&lt;/li&gt;
&lt;li&gt;Cryptocurrency prices&lt;/li&gt;
&lt;li&gt;Collateral Ratio&lt;/li&gt;
&lt;li&gt;DeFi Protocol Fees&lt;/li&gt;
&lt;li&gt;Blockchain Transaction fees&lt;/li&gt;
&lt;li&gt;Number of users&lt;/li&gt;
&lt;li&gt;Blockchain transaction throughput&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Exogenous:&lt;/strong&gt; A variable determined outside the model that is imposed on the model. In MakerDao’s DAI, the asset price of the collateral(ETH/USDC) is independent of the MakerDAO system.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Endogenous Variable:&lt;/strong&gt; A variable determined by the model. In Synthetix, arbitrary derivatives are backed by SNX(a project internal token)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fractional Reserve:&lt;/strong&gt; When a bank only has a fraction of its deposits backed by cash and available for withdrawal. A bank’s reserve ratio = Money held by the bank / Money deposited by bank customers&lt;/p&gt;
&lt;h2 id=&quot;what-is-stability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-is-stability&quot; aria-label=&quot;what is stability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What is Stability?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Stability is a relative metric. USD is stable compared to bitcoin but the price still fluctuates with respect to other assets.&lt;/li&gt;
&lt;li&gt;We can measure volatility, the standard deviation of returns, and the worst drop over a timeframe. Some fiat, for example euros or pounds, have a volatility of 6-12%. However, volatility alone does not capture the range of prices.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;stable-vs-pegged-coins&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#stable-vs-pegged-coins&quot; aria-label=&quot;stable vs pegged coins permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Stable vs Pegged Coins&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Stablecoins include USDC, USDT, DAI, UST, etc. These coins are simply USD derivatives and are usually reserve based, collateral based, or algorithmic.&lt;/li&gt;
&lt;li&gt;Pegged coins include wBTC, renBTC, sETH, stETH. They are pegged to the price of an asset, usually via the same reserved based, collateral based, or algorithmic strategies used by stablecoins.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-do-stablecoins-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-do-stablecoins-work&quot; aria-label=&quot;how do stablecoins work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How do Stablecoins work?&lt;/h2&gt;
&lt;h3 id=&quot;makerdaos-dai&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#makerdaos-dai&quot; aria-label=&quot;makerdaos dai permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;MakerDAO’s DAI&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;The minter deposits ETH to open a collateralized debt position (CDP) where 150% collateral mints 100% debt. The collateral in this case could be ETH, and the debt create is represented as the DAI Stablecoin.&lt;/li&gt;
&lt;li&gt;The minter can withdraw DAI to use for anything they want.&lt;/li&gt;
&lt;li&gt;To get their deposited ETH back, the minter needs to pay back the same amount of DAI they withdrew to unlock their ETH.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;synthetix-susd&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#synthetix-susd&quot; aria-label=&quot;synthetix susd permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Synthetix sUSD&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;The minter deposits SNX to mint a derivative. 600% collateral mints 100% derivative. The collateral in this case is always SNX, and the derivative could be something like sUSD or even something like sTSLA shares.&lt;/li&gt;
&lt;li&gt;The minter can withdraw their derivative. In the case of sTSLA, price oracles report the external prices to the blockchain, which entitles the derivative to a portion of the collateral based on the current price of TSLA shares.&lt;/li&gt;
&lt;li&gt;The minter can pay back their sTSLA to unlock SNX&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;ampleforth-ampl&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ampleforth-ampl&quot; aria-label=&quot;ampleforth ampl permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Ampleforth (AMPL)&lt;/h2&gt;
&lt;p&gt;Ampleforth has no collateral, it is an algorithmic stablecoin
The price oracle constantly updates the AMPL/USD price. There are three cases the oracle reports:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If each AMPL is worth more than 1 USD, wallet balances that hold ample increase. For example, if you had one AMPL in your wallet and each AMPL is now worth 2 USD, you now have two AMPL in your wallet. This is known as expansion.&lt;/li&gt;
&lt;li&gt;If each AMPL is worth less than 1 USD, wallet balances that hold AMPL decrease. For example, if you had one AMPL in your wallet and each AMPL is now worth .5 USD, you now have .5 AMPL in your wallet. This is known as contraction.&lt;/li&gt;
&lt;li&gt;If each AMPL is worth exactly 1 USD, no action is taken. This is known as equilibrium.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;remaining-questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#remaining-questions&quot; aria-label=&quot;remaining questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Remaining Questions&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;Even though AMPL is 1:1 USD, why is it worth anything? It isn’t backed by collateral like DAI/USDC so what can you do with AMPL? How is AMPL minted?&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[The Merge]]></title><description><![CDATA[A quick primer on the merge for ethereum 2.0]]></description><link>https://albertsu.netlify.app//posts/crypto/borrow</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/borrow</guid><pubDate>Thu, 30 Dec 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;the-merge&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-merge&quot; aria-label=&quot;the merge permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Merge&lt;/h1&gt;
&lt;p&gt;Transition from Proof of Work to Proof of stake&lt;/p&gt;
&lt;h2 id=&quot;proof-of-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#proof-of-work&quot; aria-label=&quot;proof of work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Proof of Work&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Looking for some amount of leading zeroes, aka your hash should be less than some value&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;proof-of-stake&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#proof-of-stake&quot; aria-label=&quot;proof of stake permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Proof of Stake&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Blocks constructed by leaders proposes block to committee, committee confirms the block&lt;/li&gt;
&lt;li&gt;Beacon chain: currently running in parallel to main POW chain and holds staking balances for ETH POS&lt;/li&gt;
&lt;li&gt;Will be merged into the main chain &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;sharding&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sharding&quot; aria-label=&quot;sharding permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sharding&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Sharding splits a database into separate shards so nodes don’t have to store full database&lt;/li&gt;
&lt;li&gt;Shards initially will only be a data layer, doesn’t support execution&lt;/li&gt;
&lt;li&gt;Sharding can be used for execution via ZK rollups bc only proof needs to be stored&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;difficulty-bomb&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#difficulty-bomb&quot; aria-label=&quot;difficulty bomb permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Difficulty Bomb&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Hardcoded in eth, increases difficulty for block production, making it virtually impossible for miners to produce blocks&lt;/li&gt;
&lt;li&gt;Will hit when the merge takes place via the bellatrix hard fork and POS validators take over&lt;/li&gt;
&lt;li&gt;Shards would launch later&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;ropsten-drama&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ropsten-drama&quot; aria-label=&quot;ropsten drama permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Ropsten Drama&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Difficulty Bomb hits when the cumulative difficulty reaches a certain point. On ropsten, someone brought a ton of hash power to increase cumulative difficulty which made the difficulty bomb hit early&lt;/li&gt;
&lt;li&gt;Beacon chain wasn’t yet there, normal chain can’t produce blocks bc difficulty bomb&lt;/li&gt;
&lt;li&gt;On May 26th, there was a 7 block reorg. Reorgs are bad because they break many security assumptions on dapps, like oracles. Crypto Twitter suspects that this is due to people using different clients, some outdated, some current&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;consecutive-block-production-by-leaders&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#consecutive-block-production-by-leaders&quot; aria-label=&quot;consecutive block production by leaders permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Consecutive Block Production By Leaders&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;In POW, it’s extremely unlikely for two miners to form more than one block in a row without a significant portion of the network hash power(selfish mining)&lt;/li&gt;
&lt;li&gt;Leaders in proof of stake would know that they are going to form a block in advance, so they would know when they could form two blocks in a row, and thus cause a reorg&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[File Systems]]></title><description><![CDATA[Notes on File Systems]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/file-systems</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/file-systems</guid><pubDate>Sat, 20 Nov 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;what-does-a-storage-system-need&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-does-a-storage-system-need&quot; aria-label=&quot;what does a storage system need permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What does a storage system need?&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; User data should be safely stored even if a machine’s power is turned off or the OS crashes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Large Capacity and Low Cost&lt;/strong&gt; It takes 350 MB for an hour of music, 1 GB for 300 photos, and 4GB to store an hour long video. Many individuals own 1 TB or more of storage for personal files.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High performance:&lt;/strong&gt; Programs must have quick access to data to satiate users(ie computer starting up, youtube serving video, amazon processing orders)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Named data:&lt;/strong&gt; Data must be organized for future retrieval, the easiest way is to name the file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Controlled Sharing:&lt;/strong&gt; Users want to share stored data, but only with the right people.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;how-does-a-file-system-help&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-does-a-file-system-help&quot; aria-label=&quot;how does a file system help permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How does a file system help?&lt;/h2&gt;
&lt;p&gt;Non-volatile storage is much slower than DRAM, also, access must be done in coarse grained units, 512 bytes or more at a time.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Goal: High performance&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Physical Characteristic: Large cost to initiate I/O access&lt;/li&gt;
&lt;li&gt;Organize data placement with files, directories, the free space bitmap(free map), and placement heuristics so that storage is accessed in large sequential units&lt;/li&gt;
&lt;li&gt;Use Caching to avoid accessing persistent storage&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Goal: Named data&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Physical Characteristic: Storage has large capacity, survive crashes, and is shared across programs&lt;/li&gt;
&lt;li&gt;Support files and directories with meaningful names&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Goal: Controlled Sharing&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Physical Characteristic: Device stores many users’ data&lt;/li&gt;
&lt;li&gt;Include access control metadata with files&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Goal: Reliable Storage&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Physical Characteristic: Crashes can occur during updates. Storage devices can fail. Flash memory cells can wear out&lt;/li&gt;
&lt;li&gt;Use transactions to make a set of updates atomic&lt;/li&gt;
&lt;li&gt;Use redundancy to detect and correct failures&lt;/li&gt;
&lt;li&gt;Move data to different storage locations to evenly wear out the disk&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;why-is-it-important-to-know-how-file-systems-work-even-if-im-not-building-a-file-system&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-is-it-important-to-know-how-file-systems-work-even-if-im-not-building-a-file-system&quot; aria-label=&quot;why is it important to know how file systems work even if im not building a file system permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why is it important to know how file systems work even if I’m not building a file system?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Performance:&lt;/strong&gt; Even though file systems allow existing bytes in a file to be overwritten, inserting new bytes may require rewriting the entire file. Thus, autosaving may take as much as a second.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Corrupt Files&lt;/strong&gt; When overwriting the existing file with updated data, an untimely crash can leave the file in an inconsistent state, containing a combination of old and new versions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lost files&lt;/strong&gt; If instead of overwriting the document file, the applications writes to a new file, then deletes the original file, then moves the new file to the original file location, an untimely crash can leave the system with no copies of the document at all.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;the-file-system-abstraction&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-file-system-abstraction&quot; aria-label=&quot;the file system abstraction permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The File System Abstraction&lt;/h1&gt;
&lt;p&gt;An OS abstraction that provides persistent named data.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;File:&lt;/strong&gt; named collection of data in a file system. It is an arbitrary size, consisting of metadata and data. From the POV of the file system, a file’s data is just an array of untyped bytes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Directory:&lt;/strong&gt; Provides names for files. Contains a list of human readable names and a mapping from each name to a specific file or directory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hard link:&lt;/strong&gt; Mapping between a name and the underlying file&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Soft link:&lt;/strong&gt; Mapping from a file name to another file name. Unfortunately, this can cause dangling links: ie you link /a to point to /b which points to hi.txt then you unlink /b, /a will dangle)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Volume:&lt;/strong&gt; A collection of physical storage resources that form a logical storage device. This is usually an abstraction that corresponds to a logical disk.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mounting:&lt;/strong&gt; Create a mapping from some path in the existing file system to the root directory of the mounted volume’s file path. Used when plugging in USB drive to your computer&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;the-file-system-api&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-file-system-api&quot; aria-label=&quot;the file system api permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The File System API&lt;/h1&gt;
&lt;h2 id=&quot;creating-and-deleting-files&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#creating-and-deleting-files&quot; aria-label=&quot;creating and deleting files permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Creating and Deleting Files&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;Create()&lt;/code&gt; creates a new file that has initial metadata but no other data and it creates a name for the file in a directory&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;Link()&lt;/code&gt; creates a hard link(new path name for existing file). After calling link(), there should be multiple path names that refer to the same underlying file. You cannot call link() on a directory&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;Unlink()&lt;/code&gt; removes a file from its directory. If there are multiple links to a file, unlink() removes the specified name. If there is only one link to a file, unlink() also deletes the underlying file and frees the resources.&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;mkdir()&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;rmdir()&lt;/code&gt; creates and deletes directories.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;open-and-close&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#open-and-close&quot; aria-label=&quot;open and close permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Open and close&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;open()&lt;/code&gt; a process calls open() to get a file descriptor it can use to refer to the open file.&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;close()&lt;/code&gt; releases the open file record in the OS&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;file-access&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#file-access&quot; aria-label=&quot;file access permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;File access&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;read()&lt;/code&gt; starts from the process’s current file position and advances it by the number of bytes successfully read or written. Reads bytes&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;write()&lt;/code&gt;starts from the process’s current file position and advances it by the number of bytes successfully read or written. Writes bytes&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;seek()&lt;/code&gt; changes a process’ current position for a specified open file&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;mmap()&lt;/code&gt; establish a mapping between a region of the process’s virtual memory and some region of the file so that memory loads and stores to that virtual memory region will use the kernel’s file cache or triggers a Page fault exception which causes the kernel to fetch the desire page from the file system to memory&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;munmap()&lt;/code&gt; remove mapping created by mmap()&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;fsync()&lt;/code&gt; Ensures all pending updates for a file are written to persistent storage before the call returns. Used to ensure that updates are durable and will not be lost in case of crash. If fsync() is called twice, the first is written to persistent storage before the second.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;software-layers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#software-layers&quot; aria-label=&quot;software layers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Software Layers&lt;/h1&gt;
&lt;h2 id=&quot;api-and-performance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#api-and-performance&quot; aria-label=&quot;api and performance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;API and Performance&lt;/h2&gt;
&lt;h3 id=&quot;system-calls-and-libraries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#system-calls-and-libraries&quot; aria-label=&quot;system calls and libraries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;System calls and libraries&lt;/h3&gt;
&lt;p&gt;Application libraries wrap syscalls mentioned above in the file system API to add additional functionality such as buffering.&lt;/p&gt;
&lt;h3 id=&quot;block-cache&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#block-cache&quot; aria-label=&quot;block cache permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Block Cache&lt;/h3&gt;
&lt;p&gt;Since storage devices are much slower than DRAM, the OS has a block cache that caches recently read blocks and buffers recently written blocks.&lt;/p&gt;
&lt;h3 id=&quot;prefetching&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#prefetching&quot; aria-label=&quot;prefetching permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Prefetching&lt;/h3&gt;
&lt;p&gt;When a process reads the first two blocks of a file, the OS may prefetch the first 10 blocks. When the predictions are accurate, it can reduce latency from future reads(by returning the contents in the cache), reduce device overhead(by replacing a large number of small requests with one large one), and improve parallelism(by allowing hardware to process multiple requests at once in parallel).&lt;/p&gt;
&lt;p&gt;Some disadvantages of prefetching include cache pressure(each prefetched block might displace another block in the block cache which might be more useful), I/O contention(prefetching costs IO, other requests might need to wait behind prefetch requests), and wasted effort(the prefetched blocks are not actually used).&lt;/p&gt;
&lt;h2 id=&quot;device-drivers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#device-drivers&quot; aria-label=&quot;device drivers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Device Drivers&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Used to translate the high level abstractions implemented by the OS and IO devices.&lt;/li&gt;
&lt;li&gt;Layering helps simplify OS by providing a common way to access various classes of devices.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;memory-mapped-io&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#memory-mapped-io&quot; aria-label=&quot;memory mapped io permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Memory Mapped IO&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;IO devices typically have a controller with a set of registers that can be written and read to transmit commands and data to and from the device.&lt;/li&gt;
&lt;li&gt;Memory Mapped IO maps each device’s control registers to a range of physical addresses on the memory bus. Reads and writes by the CPU to this physical address range go to the IO device’s controllers instead of main memory&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;dma&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#dma&quot; aria-label=&quot;dma permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;DMA&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Most IO devices transfer data in bulk. Rather than requiring the CPU to read or write each word of a large transfer, IO devices can use direct memory accesses(DMA).&lt;/li&gt;
&lt;li&gt;DMA allows the IO device to copy a block of data between its own internal memory and the system’s main memory.&lt;/li&gt;
&lt;li&gt;The OS uses memory mapped IO to set up a DMA transfer, then the device copies data to or from the target address without additional processor involvement&lt;/li&gt;
&lt;li&gt;After setting up a DMA transfer, the OS must not use the target physical pages for any other purpose until the DMA transfer is done.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;lifecycle-of-a-disk-request&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lifecycle-of-a-disk-request&quot; aria-label=&quot;lifecycle of a disk request permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lifecycle of a Disk Request&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;When a process issues a system call like read() to read data from disk into the process’s memory, the operating system moves the calling thread to a wait queue.&lt;/li&gt;
&lt;li&gt;Then, the operating system uses memory-mapped I/O both to tell the disk to read the requested data and to set upDMA so that the disk can place that data in the kernel’s memory. - The disk then reads the data and DMAs it into main memory; once that is done, the disk triggers an interrupt.&lt;/li&gt;
&lt;li&gt;The operating system’s interrupt handler then copies the data from the kernel’s buffer into the process’s address space.&lt;/li&gt;
&lt;li&gt;Finally, the operating system moves the thread the ready list.&lt;/li&gt;
&lt;li&gt;When the thread next runs, it will returns from the system call with the data now present in the specified buffer.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;files-and-directories&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#files-and-directories&quot; aria-label=&quot;files and directories permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Files and Directories&lt;/h1&gt;
&lt;p&gt;Motivation: How do we go from a file name and offset to a block number?
Naive Approach: The file system is a dictionary that maps keys(file name and offset) to values(block number)&lt;/p&gt;
&lt;h2 id=&quot;challenges-with-building-a-file-system&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#challenges-with-building-a-file-system&quot; aria-label=&quot;challenges with building a file system permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Challenges with building a file system&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt; File systems need good spatial locality, where blocks that are accessed together are stored sequentially. The naive approach would just map block numbers in random places.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexibility&lt;/strong&gt; File systems allow apps to share data, and thus must let people access small files, large files, short-lived files, and anything in between.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Persistence&lt;/strong&gt; File systems must maintain and update both user data and internal data structures through OS crashes and power failures&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reliability&lt;/strong&gt; File systems must store data for long periods of time&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;file-system-implementation-overview&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#file-system-implementation-overview&quot; aria-label=&quot;file system implementation overview permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;File System Implementation Overview&lt;/h2&gt;
&lt;p&gt;Most file systems have directories, index structures, free space maps, and locality heuristics.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Directories&lt;/strong&gt; A way to map human readable file names to file numbers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Index structures&lt;/strong&gt; A way to translate the file number to locate the blocks of the file. This is usually some form of tree.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Free space maps&lt;/strong&gt; Tracks which storage blocks are free and which are in use as files grow and shrink. Also, blocks returned must have good spatial locality. Usually implemented as bitmaps&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Locality Heuristics&lt;/strong&gt; Policies that group data to optimize performance. Some file systems group by directory, others periodically defragment their storage by rewriting existing files so that each file is stored in sequential blocks.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;directories&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#directories&quot; aria-label=&quot;directories permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Directories&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Purpose&lt;/strong&gt; Translate human readable names to internal file numbers in a mapping&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implementation&lt;/strong&gt; Stored as a file&lt;/li&gt;
&lt;li&gt;The root directory’s file number is agreed upon ahead of time, for the Unix Fast File System it is 2.&lt;/li&gt;
&lt;li&gt;To read &lt;code class=&quot;language-text&quot;&gt;/home/albert/hi.txt&lt;/code&gt; we search the root directory by reading the file associated with file number 2. In file2 , we search for the name &lt;code class=&quot;language-text&quot;&gt;home&lt;/code&gt; and find that /home is stored in file number 880. In file 880, we search for the name &lt;code class=&quot;language-text&quot;&gt;albert&lt;/code&gt; and find /home/albert is stored in 526. In file 526, we search for &lt;code class=&quot;language-text&quot;&gt;hi.txt&lt;/code&gt;, we find /home/albert/hi.txt is in file number 469&lt;/li&gt;
&lt;li&gt;The directory API is different from the standard open/read/close/write, since the file name to file number mapping cannot be corrupted&lt;/li&gt;
&lt;li&gt;The syscalls that modify directories are &lt;code class=&quot;language-text&quot;&gt;mkdir&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;link&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;unlink&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;rmdir&lt;/code&gt;. Mkdir and rmdir create and delete the directory, &lt;code class=&quot;language-text&quot;&gt;link(&quot;hi.txt&quot;, &quot;new.txt&quot;)&lt;/code&gt; creates a hard link to an existing file, &lt;code class=&quot;language-text&quot;&gt;unlink(&quot;hi.txt&quot;)&lt;/code&gt; removes that hard link.&lt;/li&gt;
&lt;li&gt;Processes can read the contents of directory files using the standard file read syscall&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;hard-vs-soft-links&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#hard-vs-soft-links&quot; aria-label=&quot;hard vs soft links permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Hard vs Soft Links&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hard Links&lt;/strong&gt; Multiple file directory entries that map different path names to the same file number. File systems must ensure that a file is only deleted when the last hard link is removed.&lt;/li&gt;
&lt;li&gt;File systems use reference counts that count the number of hard links to each file, starting with 1 at creation. Each call to &lt;code class=&quot;language-text&quot;&gt;link()&lt;/code&gt; increases the reference count by 1 and each call to &lt;code class=&quot;language-text&quot;&gt;unlink()&lt;/code&gt; decreases the reference count by 1&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Soft Links&lt;/strong&gt; are directory entries that map one name to another name&lt;/li&gt;
&lt;li&gt;If the file system supports hard links, storing file metadata in directory entries would be problematic since whenever the file size changes, all the file’s directory entries need to be updated&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;files&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#files&quot; aria-label=&quot;files permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Files&lt;/h2&gt;
&lt;p&gt;Purpose: Translate a file number to the blocks that belong to the file
Goals:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Put data blocks sequentially to maximize spatial locality&lt;/li&gt;
&lt;li&gt;Provide efficient random access to any file block&lt;/li&gt;
&lt;li&gt;Limit overhead to be efficient for smaller files&lt;/li&gt;
&lt;li&gt;Be scalable to support large files&lt;/li&gt;
&lt;li&gt;Provide a place to store metadata, ie reference count, owner, access control list, size&lt;/li&gt;
&lt;/ol&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File System&lt;/th&gt;
&lt;th&gt;Index Structure&lt;/th&gt;
&lt;th&gt;Free Space Management&lt;/th&gt;
&lt;th&gt;Locality Heuristics&lt;/th&gt;
&lt;th&gt;Index Structure Granularity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;FAT(USB drives)&lt;/td&gt;
&lt;td&gt;Linked List&lt;/td&gt;
&lt;td&gt;FAT array&lt;/td&gt;
&lt;td&gt;Defragmentation&lt;/td&gt;
&lt;td&gt;Block&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FFS(Unix)&lt;/td&gt;
&lt;td&gt;Tree(fixed, assymmetric)&lt;/td&gt;
&lt;td&gt;Bitmap(fixed)&lt;/td&gt;
&lt;td&gt;Block groups, reserve space&lt;/td&gt;
&lt;td&gt;Block&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NTFS(Windows)&lt;/td&gt;
&lt;td&gt;tree(dynamic)&lt;/td&gt;
&lt;td&gt;Bitmap in file&lt;/td&gt;
&lt;td&gt;Best fit, defragmentation&lt;/td&gt;
&lt;td&gt;Extent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ZFS(Copy on write)&lt;/td&gt;
&lt;td&gt;tree(copy on write, dynamic)&lt;/td&gt;
&lt;td&gt;Space map(log-structured)&lt;/td&gt;
&lt;td&gt;Write anywhere, block groups&lt;/td&gt;
&lt;td&gt;Block&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;fat-filesystem&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fat-filesystem&quot; aria-label=&quot;fat filesystem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;FAT Filesystem&lt;/h3&gt;
&lt;!-- ![File allocation table](/media/File-Systems/FAT.JPG) --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Techniques&lt;/strong&gt; Uses a extremely simple index structure(linked list). FAT stands for file allocation table, its array of 32 bit entries in a reserved area of the volume. Each file corresponds to a FAT entry in the array, which is either the last block or contains a pointer to the next block.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Directories&lt;/strong&gt; map file names to file numbers. The file’s number is the index of the file’s first entry in the FAT. We can then parse the linked list to find the rest of the file’s blocks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Free space tracking&lt;/strong&gt; If data block i is free, then FAT[i] = 0&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Locality Heuristics&lt;/strong&gt; Some FAT implementations use a next fit algorithm that sequentially scans the file allocation table starting from the last entry and returns the next free entry. This fragments the file, so there is often a defragmentation tool that reads files from their existing locations and rewrites them for better spatial locality.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limitations&lt;/strong&gt;: Poor locality(badly fragmented files), Poor random access(need to sequentially traverse the FAT entries), limited metadata and no access control, no support for hard links, limitations on volume and file size(max file size if 4GB), and a lack of support for reliability techniques(does not support transactional updates).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;unix-fast-file-systemffs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#unix-fast-file-systemffs&quot; aria-label=&quot;unix fast file systemffs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Unix Fast File System(FFS)&lt;/h3&gt;
&lt;!-- ![Multilevel index](/media/File-Systems/multilevel-index.JPG) --&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Techniques&lt;/strong&gt; FFS uses a carefully structured tree that locates any block of a file that is efficient for both large and small files. Each file is a tree with fixed size blocks as its leaves. Each file’s tree is rooted in an &lt;em&gt;inode&lt;/em&gt; that contains the file metadata.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Typically the file’s inode contains 15 pointers: the first 12 pointers are direct pointers that point directly to the first 12 data blocks of a file&lt;/li&gt;
&lt;li&gt;The 13th pointer in the &lt;em&gt;inode&lt;/em&gt; is an indirect pointer which points to an array of direct pointers.&lt;/li&gt;
&lt;li&gt;The 14th pointer in the *inode is a double indirect pointer which points to an internal node which points to an array of indirect pointers, each pointing to an array of direct pointers.&lt;/li&gt;
&lt;li&gt;The 15th pointer in the inode is a triple indirect pointer that contains an array of double indirect pointers.&lt;/li&gt;
&lt;li&gt;All of the file system’s inodes are located in an inode array. The file’s file number, aka &lt;em&gt;inumber&lt;/em&gt; is an index into the inode array.&lt;/li&gt;
&lt;li&gt;This asymmetric setup allows for efficient support for both large and small files.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Free Space Management&lt;/strong&gt; FFS allocates a bitmap with one bit per storage block, the ith bit in the bitmap indicates whether the ith block is free or in use.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Locality Heuristics&lt;/strong&gt; FFS uses block group placement and reserved space&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;block group placement&lt;/em&gt; divides the disk into block groups so the seek time between any blocks in a block group will be small  &lt;/p&gt;
&lt;!-- ![Block Group Placement](/media/File-Systems/block-group-placement.JPG) --&gt;
&lt;/li&gt;
&lt;li&gt;Each block group holds a portion of the metadata structures&lt;/li&gt;
&lt;li&gt;FFS puts a directory and its files in the same block group&lt;/li&gt;
&lt;li&gt;Within a block group, FFS writes to the first free block in the file’s block group. This helps locality in the long term since fragmentation is reduced&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;When the disk’s space is almost full, the block group heuristic will perform poorly since new writes will be scattered randomly around the disk. Thus, FFS reserves a portion of the disk’s space and presents a slightly reduced disk size to applications&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;windows-new-technology-file-systemntfs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#windows-new-technology-file-systemntfs&quot; aria-label=&quot;windows new technology file systemntfs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Windows New Technology File System(NTFS)&lt;/h3&gt;
&lt;p&gt;Instead of using fixed trees like FFS, NTFS uses extents and flexible trees&lt;/p&gt;
&lt;!-- ![NTFS index record](/media/File-Systems/nfts-index-record.JPG) --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Extent&lt;/strong&gt; variable sized regions of files that are stored in a contiguous region on the storage device&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexible tree and master file table&lt;/strong&gt; Each file in NTFS is represented by a variable depth tree. The extent pointers for a file with a small number of extents can be stored in a shallow tree, deeper trees are only needed if the file becomes badly fragmented.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Master File Table(MFT)&lt;/strong&gt; stores an array of 1KB MFT records, each of which stores a sequence of variable size attribute records.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resident attribute&lt;/strong&gt; Stores its contents directly in the MFT record&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-resident attribute&lt;/strong&gt; Stores extent pointers in its MFT record and stores its contents in those extents.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MFT record&lt;/strong&gt; Includes standard information(creation time, last modified, owner ID), file name, and attribute list&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Four stages of file growth&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Small files can have their contents included in the MFT record as a resident data attribute.&lt;/li&gt;
&lt;li&gt;Normal file data has a small number of extents tracked by a single non-resident data attribute.&lt;/li&gt;
&lt;li&gt;Large files combined with a fragmented file system can make a file have so many extents that the extent pointers will not fit in a single MFT record. These files can have multiple non-resident data attributes in multiple MFT records, with the attribute list in the first MFT record indicating which MFT record tracks which range of extents&lt;/li&gt;
&lt;li&gt;If the file is huge, the file attribute list can be made non-resident, allowing arbitrarily large numbers of MFT records&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Free Space Map&lt;/strong&gt;
NTFS stores all metadata in a dozen files with low file numbers. For example, file number 5 is the root, file number 6 is the free space bitmap, file number 8 contains a list of the volume’s bad blocks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Locality Heuristics&lt;/strong&gt; NFTS uses best fit, where the system tries to place a newly allocated file in the smallest free region large enough to hold it. NTFS also has a defragmentation utility&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;copy-on-write-cow&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#copy-on-write-cow&quot; aria-label=&quot;copy on write cow permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Copy on Write (COW)&lt;/h3&gt;
&lt;p&gt;When updating an existing file, COW file systems do not overwrite existing data or metadata, instead, they write new versions to new locations.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Motivations&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Small writes are expensive. Large sequential writes is much better than small random writes, and the gap will continue to grow since bandwidth grows faster than seek time/rotational latency&lt;/li&gt;
&lt;li&gt;Small writes are expensive on raid since we need to read old data, read old parity, write new data, and write new parity. The number of times we read/write to parity bits grows linearly with the number of reads/write but not the size of the reads/writes&lt;/li&gt;
&lt;li&gt;Large DRAM caches can handle essentially all file reads, thus the cost of writes dominate performance so optimizing write performance is the number one priority.&lt;/li&gt;
&lt;li&gt;Flash storage works better with copy on write: there is no need to clear the erasure block and it writes data to a different location instead of overwriting the current data wearing out the flash drive evenly&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Since old data isn’t overwritten, we can support versioning&lt;/p&gt;
&lt;!-- ![Copy on Write](/media/File-Systems/copy-on-write.JPG) --&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implementation:&lt;/strong&gt; We store inodes in a file rather than in the inode array. All the file system’s contents are stored in a tree rooted in the root inode, when we update a block, we write the block and all of the blocks on the path from it to the root to new locations.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;zfs-file-system&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#zfs-file-system&quot; aria-label=&quot;zfs file system permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;ZFS file system&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;uberblock&lt;/strong&gt; the root of the ZFS storage system, ZFS has an array of 256 uberblocks and rotates successive versions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;dnode&lt;/strong&gt; similar to inode, a file represented by a variable depth tree whose root is a dnode and leaves are data blocks&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Free space map&lt;/strong&gt; per block group space maps. ZFS maintains a space map for each block group, has a tree of extents, and log structured updates.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Locality Heuristics&lt;/strong&gt; On writes, ZFS ensures sequential writes and batched updates.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;file-and-directory-access-walkthrough&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#file-and-directory-access-walkthrough&quot; aria-label=&quot;file and directory access walkthrough permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;File and Directory Access Walkthrough&lt;/h2&gt;
&lt;!-- ![Walkthrough](/media/File-Systems/walkthrough.JPG) --&gt;
&lt;p&gt;Goal: Read the file /foo/bar/baz
Steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Read the root directory &lt;code class=&quot;language-text&quot;&gt;/&lt;/code&gt; to determine &lt;code class=&quot;language-text&quot;&gt;/foo&lt;/code&gt;’s inumber&lt;/li&gt;
&lt;li&gt;Open and read file 2’s inode. Since FFS stores pieces of the inode array at fixed locations on disk, given a file’s inumber it is easy to read the file’s inode&lt;/li&gt;
&lt;li&gt;From the root directory’s inode, extract the direct and indirect block pointers to determine which block stores the contents of the root directory.(block 48912)&lt;/li&gt;
&lt;li&gt;Read that block of data to get the list of name to inumber mappings in the root directory to find &lt;code class=&quot;language-text&quot;&gt;/foo&lt;/code&gt; has inumber 231&lt;/li&gt;
&lt;li&gt;Since we know &lt;code class=&quot;language-text&quot;&gt;/foo&lt;/code&gt;’s inumber, we read inode 231 to find where &lt;code class=&quot;language-text&quot;&gt;/foo&lt;/code&gt;’s data blocks are stored-block 1094 in this example.&lt;/li&gt;
&lt;li&gt;Read block 1094 to get the list of name to inumber mappings in the &lt;code class=&quot;language-text&quot;&gt;/foo&lt;/code&gt; directory to find that the directory file &lt;code class=&quot;language-text&quot;&gt;/foo/bar&lt;/code&gt; has inumber 731.&lt;/li&gt;
&lt;li&gt;Follow similar steps to read &lt;code class=&quot;language-text&quot;&gt;/foo/bar&lt;/code&gt;’s inode and data block 30991 to find &lt;code class=&quot;language-text&quot;&gt;/foo/bar/baz&lt;/code&gt;’s inumber is 402&lt;/li&gt;
&lt;li&gt;Read &lt;code class=&quot;language-text&quot;&gt;/foo/bar/inode&lt;/code&gt; to get the data blocks 89310, 14919, 23301&lt;/li&gt;
&lt;li&gt;Usually, data blocks are cached so we don’t need to repeat this process.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;What does mmap() do?&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Reliable Storage]]></title><description><![CDATA[Notes on Reliable Storage]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/reliable-storage</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/reliable-storage</guid><pubDate>Sat, 20 Nov 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;why-do-we-need-reliable-storage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-do-we-need-reliable-storage&quot; aria-label=&quot;why do we need reliable storage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why do we need reliable storage?&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Physical devices may fail, they may wear out, they may become damaged. Large organizations see annual disk failure rates of 2-4%, which means that over 10 years 30% of the data in the disk would be gone&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Two threats to reliability&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Operation Interruption:&lt;/strong&gt; A crash or power failure in the middle of a series of related updates leaves the data in an inconsistent state. Ie crashing when moving a file so we now have two copies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Solution&lt;/strong&gt; Create transactions for atomic updates.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loss of stored data:&lt;/strong&gt; Failure of non-volatile storage media can cause stored data to become corrupted or disappear&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Solution&lt;/strong&gt; Create redundancy for failures, ie RAID or using multiple layers of checksums&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reliability-availability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reliability-availability&quot; aria-label=&quot;reliability availability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Reliability, Availability,&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Reliable:&lt;/strong&gt; Can the system perform the intended function? A system can be available but not working properly. Can increase reliability by testing system.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Available:&lt;/strong&gt; Can the system respond to a request? Also known as the percentage of time when the system is up. Can achieve higher availability with deploying apps across multiple geographically distant servers using load balancing to reroute requests to healthy servers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durability:&lt;/strong&gt; Is the data still in the system? A system is durable even if you can’t access the data(ie bury a usb underground). Can achieve higher durability by making backups, storing in different geographical area, performing checksums.&lt;/li&gt;
&lt;li&gt;A data block replicated across 100 machines is highly reliable and highly available for reads, but not highly available for writes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;transactions--atomic-updates&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transactions--atomic-updates&quot; aria-label=&quot;transactions  atomic updates permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transactions + Atomic Updates&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Problem:&lt;/strong&gt; When the system crashes in the middle of several updates, the data in the system might not make sense or leaves it in a vulnerable. For example, bob is transferring 100 dollars to alice and the bank database crashes, it could have crashed when the bank pulled 100 dollars out of bob’s account but before it sent the 100 dollars to alice’s account. Now, bob just lost 100 dollars&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Naive Solutions:&lt;/strong&gt; The unix fast file system would control the order of updates such that if a crash occurred, it could scan the disk during recovery and identify and repair inconsistent data structures. Now if this sounds kind of sketchy, it is and there were three main problems with it.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Extremely slow recovery:&lt;/strong&gt; When the machine reboots, it has to scan all of its disks for inconsistent metadata structures.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slow Updates&lt;/strong&gt; To ensure the unix fast file system updates were analyzable, they had to be ordered correctly, making it hard to parallelize the stream of requests to storage devices&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Complex reasoning&lt;/strong&gt; We need to consider all possible failure scenarios to make sure that it is always possible to recover the system to a consistent state.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application Level Approaches&lt;/strong&gt; The POSIX api first writes updates to a temporary file, then renames the temporary file to atomically replace the previously stored file.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-transaction-abstraction&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-transaction-abstraction&quot; aria-label=&quot;the transaction abstraction permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Transaction Abstraction&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Problem&lt;/strong&gt; You are updating a website and you want to update files stored in &lt;code class=&quot;language-text&quot;&gt;/prod&lt;/code&gt; with files stored in &lt;code class=&quot;language-text&quot;&gt;/testing&lt;/code&gt;. However, you don’t want users to see the intermediate step where some docs in &lt;code class=&quot;language-text&quot;&gt;/prod&lt;/code&gt; are old and some are new. &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt; The transaction first does all of its changes, then commits the transaction. If at any time the transaction fails before the commit, we roll back everything done in the transaction. The benefit here is that transactions are ACID.(Yes this sounds like a dumb acronym they teach you in 6th grade to memorize the dinosaurs but this is actually an extremely well thought out acronym. ACID = transaction)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Atomicity&lt;/strong&gt; All or nothing, either a transaction commits or the system is not changed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistency&lt;/strong&gt; The transaction moves from one legal state to another. All invariants must hold at the start of the transaction and during the commit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Isolation&lt;/strong&gt; The updates within a transaction cannot interleave with other transactions. Even if multiple transactions concurrently execute, the results will be that T is executed entirely before T` or vice versa&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Durability&lt;/strong&gt; Once a transaction is committed, the only way to change state is with another transaction. Must survive crashes!&lt;/li&gt;
&lt;li&gt;Transactions are just critical sections with durability.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;transaction-implementations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transaction-implementations&quot; aria-label=&quot;transaction implementations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transaction Implementations&lt;/h2&gt;
&lt;p&gt;Problem: We want to group related writes in a single, atomic transaction but for disks and other hardware, the largest atomic operation is a single write(sector or page). Thus, we need a way to combine multiple writes into a single atomic operation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Idempotence:&lt;/strong&gt; The property where an operation can be applied multiple times without changing the result beyond the first application.&lt;/p&gt;
&lt;p&gt;Idea: A transactional system can store all of the transaction’s intentions, and the updates will only be made after all of the transaction’s intentions are written down. If we store all updates as idempotent operations, we can also start off where we finished during a crash&lt;/p&gt;
&lt;h3 id=&quot;redo-logging&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#redo-logging&quot; aria-label=&quot;redo logging permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Redo Logging&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;An implementation of transactions using four phases&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Prepare&lt;/strong&gt; Append all planned updates to the log.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Commit&lt;/strong&gt; Append a commit to the log, indicating the transaction has been committed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write-back&lt;/strong&gt; Write values in log to disk&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Garbage Collect&lt;/strong&gt; Remove transaction records from log&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the system crashes in the middle of the transaction, we scan sequentially through the log and depending on the type of record we do different things. If the record is an&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Record Type = Update&lt;/strong&gt; add this record to a list of updates for the specified transaction&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Record Type = Commit&lt;/strong&gt; Write back all of the transaction’s logged updates to disk&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Record Type = Roll-back&lt;/strong&gt; Discard list of updates for specified transaction&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Record Type = End&lt;/strong&gt; Discard all update records for transactions without commit records.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Implementation Details&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Multiple transactions might be executing at once, meaning that we need an identifier to show which transaction the log record belongs to&lt;/li&gt;
&lt;li&gt;The write-back phase can be asynchronous, meaning we can minimize latency in the commit phase and write-back multiple things at once. However, this makes crashes take longer and the log needs to take more space in the disk.&lt;/li&gt;
&lt;li&gt;Since log records are idempotent, we can reapply an update from a redo log multiple times.&lt;/li&gt;
&lt;li&gt;Restarting in recovery is ok, we just continue from where we last left off.&lt;/li&gt;
&lt;li&gt;Once write-back completes, the space in the log can be reclaimed&lt;/li&gt;
&lt;li&gt;All transaction updates must be on the log before the commit, all commits must be on disk before the write backs, all write backs must be on disk before the transaction log records can be garbage collected. &lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Performance: redo logging can have performance better than update in place, especially for small writes. Four factors allow efficient redo logging:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Log updates are sequential, so writing to spinning disks can be very fsat.&lt;/li&gt;
&lt;li&gt;Write back is asynchronous, so transactions using redo logs can have good response time and throughput&lt;/li&gt;
&lt;li&gt;The only barriers are when updates are logged and before the commit is logged, and after the commit is logged and before write-backs begin&lt;/li&gt;
&lt;li&gt;Group commits combine a set of transaction commits into one log write to amortize the cost of initiating the write&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;isolation-and-concurrency&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#isolation-and-concurrency&quot; aria-label=&quot;isolation and concurrency permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Isolation and Concurrency&lt;/h2&gt;
&lt;p&gt;To fulfill ACID properties, we need to ensure all of its properties. Redo logging only ensures durability, we also need isolation if there are multiple transactions executing at once. &lt;/p&gt;
&lt;p&gt;Naive Solution: Two phase locking divides a transaction into two phases, the expanding phase where locks can only be acquired and the contraction phase where locks can be released but not acquired.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Two phase locking results in serializability, meaning the execution is equivalent to processing the transactions one at a time.&lt;/li&gt;
&lt;li&gt;If we encounter deadlocks, we can roll back a transaction and restart at some later time. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;transactions-in-file-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transactions-in-file-systems&quot; aria-label=&quot;transactions in file systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transactions in File Systems&lt;/h2&gt;
&lt;p&gt;If the file system crashes when updating data, it could be left in an inconsistent state. Thus, all file system updates should be done in transactions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Logging:&lt;/strong&gt; Include all updates to disk in transactions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Journaling:&lt;/strong&gt; Apply metadata updates via transactions. Apply file updates normally. Ths is because file updates are idempotent&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Copy-on-write:&lt;/strong&gt; Does not overwrite data in place, but rather writes data then replaces pointer.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Copy on write systems also usually have batch updates, where you batch multiple updates into one atomic group&lt;/li&gt;
&lt;li&gt;This also has an intent log, a redo log that tracks updates between large batch updates&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;error-detection-and-correction&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#error-detection-and-correction&quot; aria-label=&quot;error detection and correction permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Error Detection and Correction&lt;/h1&gt;
&lt;p&gt;Problem: All data storage devices will fail
Solution: Use layered error detection and correction: checksums for devices, error correcting codes, RAID architectures, end to end correctness checks.&lt;/p&gt;
&lt;h2 id=&quot;types-of-storage-device-failures&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#types-of-storage-device-failures&quot; aria-label=&quot;types of storage device failures permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Types of Storage Device Failures&lt;/h2&gt;
&lt;h3 id=&quot;sector-and-page-failures&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sector-and-page-failures&quot; aria-label=&quot;sector and page failures permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sector and Page Failures&lt;/h3&gt;
&lt;p&gt;Problem: Data in the sector of a disk is lost. Flash page failures are the same thing but on SSDs.
Cause: The magnetic coating on spinning disks get scratched off, machine oil coats a sector of the spinning disk, the disk head gets too far from the surface. In flash storage, a page can get worn out from using it too many times.
Mitigation: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Error correcting codes: Encode data with redundant metadata that tells you if a sector becomes damaged&lt;/li&gt;
&lt;li&gt;Remapping: remap failed sectors to good ones
Pitfalls:&lt;/li&gt;
&lt;li&gt;Assuming that non-recoverable read error rates are negligible. A bit error rate of one sector per 10**14 bits means in a 2TB read there is a 10% chance of error&lt;/li&gt;
&lt;li&gt;Assuming non-recoverable read error rates are constant. Specific workloads can wear out some parts more than others&lt;/li&gt;
&lt;li&gt;Assuming failures are independent. Errors are usually correlated by time and space&lt;/li&gt;
&lt;li&gt;Assuming uniform error rates. Some models are just worse than others&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;device-failures&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#device-failures&quot; aria-label=&quot;device failures permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Device Failures&lt;/h3&gt;
&lt;p&gt;Problem: Device stops being able to read or write to any disk sector.
Cause: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For disks: Disk heads become damaged, power surge damages electronics. &lt;/li&gt;
&lt;li&gt;For flash devices: Wear out and device runs out of space for remapping
Mitigation: Notify the device reading the disk that there is an error
Pitfalls:&lt;/li&gt;
&lt;li&gt;Trusting advertised failure rates. Big tech lies&lt;/li&gt;
&lt;li&gt;Failures are usually correlated&lt;/li&gt;
&lt;li&gt;A mean time to failure is not the same as its useful life&lt;/li&gt;
&lt;li&gt;Failure rates are not constant, there are devices with disk infant mortality, and devices that die after wearing out&lt;/li&gt;
&lt;li&gt;Ignoring warning signs&lt;/li&gt;
&lt;li&gt;Devices don’t behave identically, even if manufactured identically.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;raid-multi-disk-redundancy-for-error-correction&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#raid-multi-disk-redundancy-for-error-correction&quot; aria-label=&quot;raid multi disk redundancy for error correction permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;RAID Multi disk redundancy for error correction&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Idea: Spread data redundantly across multiple disks in order to tolerate individual disk failures.&lt;/li&gt;
&lt;li&gt;Mirroring: The system write each block of data to two disks and can read data from either disk. If one fails, read from the other disk&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rotating Parity: store several blocks of data on several disks and protect those blocks with one redundant block stored on yet another disk.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each disk has 1 / # data blocks of its space dedicated to parity and is responsible for storing (# data blocks - 1) / # data blocks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Striping data: a strip of several sequential blocks is placed on one disk before shifting to another disk for the next strip. Thus, requests larger than a block but smaller than a strip require just one disk to seek then read/write.&lt;/li&gt;
&lt;li&gt;Recovery: If a disk suffers a sector failure, it reports it when there is an attempt to read the sector then remaps the damaged sector to a spare and reconstructs the lost sector from the other disks and rewrites it to the original disk.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ways RAID can fail&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Both disks fail&lt;/li&gt;
&lt;li&gt;One disk fails and the other disk’s sector fails&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Both disk’s sectors fail&lt;/p&gt;
&lt;h3 id=&quot;improving-raid-reliability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#improving-raid-reliability&quot; aria-label=&quot;improving raid reliability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Improving RAID Reliability&lt;/h3&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;There are three main things we can do to improve reliability: increase redundancy, reduce non recoverable read error rates, reduce mean time to repair&lt;/li&gt;
&lt;li&gt;To increase redundancy, duplicate it to 3 disks instead of 2.&lt;/li&gt;
&lt;li&gt;To reduce non-recoverable read error with scrubbing, read the entire contents of disk, find sectors with unrecoverable read errors, and reconstruct lost data from remaining RAID disks&lt;/li&gt;
&lt;li&gt;To reduce non recoverable read error rates with more reliable disks, use higher quality disks&lt;/li&gt;
&lt;li&gt;To reduce mean time to repair, use hot spares: disks that are idle but plugged into a server so that if one disk fails, the hot spare can be automatically activated&lt;/li&gt;
&lt;li&gt;Reduce mean time to repair with declustering: split the reconstruction of a failed disk accross multiple disks.&lt;/li&gt;
&lt;li&gt;Pitfalls: assuming uncorrelated failures, ignoring risk from latent errors, not implementing scrubbing, not having a backup, &lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Free Resources at UC Berkeley]]></title><description><![CDATA[List of free resources at UC Berkeley]]></description><link>https://albertsu.netlify.app//posts/misc/free-resources</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/misc/free-resources</guid><pubDate>Wed, 10 Nov 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;physical-resources&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#physical-resources&quot; aria-label=&quot;physical resources permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Physical Resources&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Free Printing:&lt;/strong&gt; Open Computing Facility(171 MLK Student Union). 100 pages of free prints per semester. Need cal id to create an account&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;If you want to build cool stuff with electronics&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Jacobs Design Institute. Useful for getting a product/UI/UX Designer&lt;/li&gt;
&lt;li&gt;Supernode&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;tech-resources&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tech-resources&quot; aria-label=&quot;tech resources permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Tech Resources&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;If you want free website hosting&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Open computing facility will host your websites for free. (&lt;a href=&quot;https://www.ocf.berkeley.edu/docs/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.ocf.berkeley.edu/docs/&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;financial-resources&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#financial-resources&quot; aria-label=&quot;financial resources permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Financial Resources&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;If you don’t know the difference between a credit and debit card&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bears for financial success(Financialaid.berkeley.edu/bffs). Useful for Identity theft, credit, debt, credit cards.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;If you do research or want to do research:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Office of Undergraduate Research and Scholarships(Research.berkeley.edu) Useful for research, scholarships related to research&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;startup-resources&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#startup-resources&quot; aria-label=&quot;startup resources permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Startup Resources&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;List of “accelerators”&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;UC Launch, Big Ideas, Citrix-Banatao, &lt;a href=&quot;https://startup.berkeley.edu/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://startup.berkeley.edu/&lt;/a&gt;, &lt;a href=&quot;https://www.dormroomfund.com/apply&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://www.dormroomfund.com/apply&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;cs-classes-resources&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cs-classes-resources&quot; aria-label=&quot;cs classes resources permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;CS Classes Resources:&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CS61A&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://alvinwan.com/publications/abcSICP.pdf&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;http://alvinwan.com/publications/abcSICP.pdf&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;before-classes-start&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#before-classes-start&quot; aria-label=&quot;before classes start permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Before Classes Start:&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Figure out who is the best GSI(Graduate Student Instruction)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;There’s a big gap between the best and work GSIs/UGSIs at Cal. Try to figure out which GSI is the best(usually a combination of semesters on course staff, if they are a head TA, if they have resources for the class that aren’t official class materials &amp;#x3C;- this one is huge because it shows that they care). Attend all of their discussion, labs, and office hours and if you do, you pretty much have at least an A- in the class.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;when-moving-to-a-new-apartment&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#when-moving-to-a-new-apartment&quot; aria-label=&quot;when moving to a new apartment permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;When moving to a new apartment&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Take a slow moving video before/right after moving in to prevent getting sued for damages&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;osmosis-office&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#osmosis-office&quot; aria-label=&quot;osmosis office permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Osmosis Office&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Osmosis has an office in berkeley, iykyk&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Input and Output]]></title><description><![CDATA[Notes on I/O]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/input-output</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/input-output</guid><pubDate>Mon, 25 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h1&gt;
&lt;p&gt;Without I/O, computers are useless. However, there are thousands of devices, each one slightly different. How do we standardize the interfaces? Devices can be unreliable(media failures/transmission errors/ packet loss), how do we make them predictable, fast, and reliable?&lt;/p&gt;
&lt;h2 id=&quot;bus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bus&quot; aria-label=&quot;bus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bus&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Common set of wires for communication among hardware devices + associated protocols to transfer data&lt;/li&gt;
&lt;li&gt;Allows for read, write&lt;/li&gt;
&lt;li&gt;Connects n devices over a single set of wires, connections, protocols O(n^2) relationships with 1 set of wires&lt;/li&gt;
&lt;li&gt;Cons: Only one transaction at a time&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-does-the-processor-talk-to-the-device&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-does-the-processor-talk-to-the-device&quot; aria-label=&quot;how does the processor talk to the device permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How does the Processor Talk to the Device?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The CPU contains a set of registers that can be read and written&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Port Mapped I/O:&lt;/strong&gt; in/out instructions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory Mapped I/O:&lt;/strong&gt; load/store instructions&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;optimal-parameters-for-io&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#optimal-parameters-for-io&quot; aria-label=&quot;optimal parameters for io permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Optimal Parameters for I/O&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data granularity:&lt;/strong&gt; Some devices provide single bytes at a time(keyboards), while other provide whole blocks (disks, networks)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access Pattern:&lt;/strong&gt; Some devices must be accessed sequentially(tape), others can be accessed randomly (disk, cd). Some devices require continual monitoring while other generate interrupts when they need service&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;transferring-data-tofrom-controller&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transferring-data-tofrom-controller&quot; aria-label=&quot;transferring data tofrom controller permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transferring Data To/From Controller&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Programmed I/O:&lt;/strong&gt; Each byte transferred via processor in/out or load/store&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pros: Simple hardware and software&lt;/li&gt;
&lt;li&gt;Cons: Consumes processor cycles proportional to data size&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Direct Memory Access:&lt;/strong&gt; Give controller access to memory bus and asks it to transfer data blocks to/from memory directly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blocking Interface:&lt;/strong&gt; When system reads data, sleep the process until the data is ready. When the system writes data, sleep the process until device is ready for data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-blocking Interface:&lt;/strong&gt; Return quickly from read/write with count of bytes transferred. It may return nothing and write may write nothing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Async Interface:&lt;/strong&gt; When reading data, take pointer to user buffer, return immediately since the kernel will fill the user buffer and notify user. When writing data, get the pointer to user buffer, return immediately. The kernel will read the data and notify the user.&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Advanced Memory Management]]></title><description><![CDATA[Notes on advanced memory management]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/memory-management</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/memory-management</guid><pubDate>Mon, 25 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;zero-copy-io&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#zero-copy-io&quot; aria-label=&quot;zero copy io permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Zero Copy I/O&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Operating systems commonly stream data between user level programs and physical devices. However, it takes a ton of time to do so since we move data from hardware to kernel then userspace or vice versa.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Potential Solutions that don’t work:&lt;/strong&gt; We could move the application into the kernel directly so the data doesn’t need to be copied from kernel to userspace. (This is not secure) We could also modify syscalls to allow applications to modify the data stored in the kernel buffer. (This isn’t flexible, it doesn’t allows for modifications)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution 1: Use the process’ page table&lt;/strong&gt; The application aligns the user level buffer to a page boundary which is then provided to the kernel. Thus, a page-to-age copy from user to kernel space can be simulated by changing page table pointers instead of physically copying memory.&lt;/p&gt;
&lt;h1 id=&quot;virtual-machines&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#virtual-machines&quot; aria-label=&quot;virtual machines permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Virtual Machines&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;A way for a host OS to run a guest OS as an application process.&lt;/li&gt;
&lt;li&gt;They are widely used on client machines to run non-native applications, are used in data centers to allow a machine to be shared by multiple machines&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;virtual-machine-page-tables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#virtual-machine-page-tables&quot; aria-label=&quot;virtual machine page tables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Virtual Machine Page Tables&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;There are two sets of page tables, guest and host&lt;/li&gt;
&lt;li&gt;The host OS provides a set of page tables to constrain the execution of the guest OS which is thinking it is running on a real OS but it is actually running on virtual memory.&lt;/li&gt;
&lt;li&gt;The host translates the guest virtual addresses into physical addresses&lt;/li&gt;
&lt;li&gt;The guest OS manages page tables for the guest processes, exactly the same as if it was on real hardware. This is because the guest OS thinks it is on real hardware.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When the host OS transfers control to the guest OS, everything works as expected.&lt;/p&gt;
&lt;p&gt;When the guest OS transfer control to the guest process, this is a privileged instruction and the hardware processor will first trap back to the host. However, we can’t use the guest OS page table, since it is using virtual addresses instead of physical addresses. Nor could we use the host OS page table since the guest OS should not have permission to modify that content. Thus, we will need to use &lt;strong&gt;Shadow Page Tables&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;shadow-page-table&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#shadow-page-table&quot; aria-label=&quot;shadow page table permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Shadow Page Table&lt;/h3&gt;
&lt;p&gt;A composite page table that represents both the guest and host page tables.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To keep the shadow page table up to date, the host needs to check if any shadow page tables need to be updated before it changes a page table entry.&lt;/li&gt;
&lt;li&gt;To keep the shadow page table up to date, the host also sets the memory of the guest page tables as read only. Thus, the guest OS traps the host every time it makes a change to a page table entry. When trapping, the host updates both the guest page table and the corresponding shadow page table.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;transparent-memory-compression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transparent-memory-compression&quot; aria-label=&quot;transparent memory compression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transparent Memory Compression&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Multiplexing multiplexors is hard. For example, a data center usually has a single physical machine running many virtual machines at the same time(ie a computer hosting multiple web sites)&lt;/li&gt;
&lt;li&gt;When a guest OS is running two copies of the same program or process, the host kernel has no way to share pages between the two instances.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Commercial Operating systems run a scavenger in the background that looks for common pages that can be shared among multiple virtual machines. Once identified, the host kernel provides an illusion that each guest has its own copy.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 843px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/b056f1282a213f528317b775f93189d6/e7b56/commercialscavanger.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 87.08333333333333%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAARABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAEF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3QUEoUH/xAAWEAADAAAAAAAAAAAAAAAAAAABECD/2gAIAQEAAQUCoP8A/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAwEBPwEf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPwEf/8QAFBABAAAAAAAAAAAAAAAAAAAAMP/aAAgBAQAGPwIf/8QAGxAAAQQDAAAAAAAAAAAAAAAAAAEQIYExUWH/2gAIAQEAAT8hsto2hHCzBkP/2gAMAwEAAgADAAAAELDAAP/EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8QH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8QH//EABwQAAICAwEBAAAAAAAAAAAAAAERACExQVEQkf/aAAgBAQABPxAbRZw4Nom7Dgd3uM+nYSjZGUcB9mH1/9k=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/b056f1282a213f528317b775f93189d6/8ac56/commercialscavanger.webp 240w,
/static/b056f1282a213f528317b775f93189d6/d3be9/commercialscavanger.webp 480w,
/static/b056f1282a213f528317b775f93189d6/e3019/commercialscavanger.webp 843w&quot;
              sizes=&quot;(max-width: 843px) 100vw, 843px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/b056f1282a213f528317b775f93189d6/09b79/commercialscavanger.jpg 240w,
/static/b056f1282a213f528317b775f93189d6/7cc5e/commercialscavanger.jpg 480w,
/static/b056f1282a213f528317b775f93189d6/e7b56/commercialscavanger.jpg 843w&quot;
            sizes=&quot;(max-width: 843px) 100vw, 843px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/b056f1282a213f528317b775f93189d6/e7b56/commercialscavanger.jpg&quot;
            alt=&quot;Commerical scavanger for memory&quot;
            title=&quot;Commerical scavanger for memory&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Case 1: Multiple copies of the same page&lt;/strong&gt;
Multiple virtual machines might share a zeroed page, it would be wasteful to create a new zeroed page for each virtual machine that needs one. The host OS instead allocates a &lt;em&gt;read-only&lt;/em&gt; zero page, which traps the host kernel when modified and allocates a new zeroed physical page for the guest OS.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They scavenger runs in the background looking for zeroed pages&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Case 2: Compression of unused pages&lt;/strong&gt;
Pages can differ by small amounts, this lets the host kernel add a layer in the memory hierarchy to save space. Instead of evicting a relatively unused page, we can save its delta with regards to the original page, and the full copy the delta is from stays read only.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the original page is modified, the delta can be quickly recompressed or evicted as necessary.&lt;/p&gt;
&lt;h1 id=&quot;fault-tolerance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fault-tolerance&quot; aria-label=&quot;fault tolerance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fault Tolerance&lt;/h1&gt;
&lt;p&gt;All systems break, but how can we manage memory to recover application data structures after a failure, not just user file data?&lt;/p&gt;
&lt;h2 id=&quot;checkpoint-and-restart&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#checkpoint-and-restart&quot; aria-label=&quot;checkpoint and restart permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Checkpoint and Restart&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Naive Solution:&lt;/strong&gt; Periodically save the program’s internal data to a file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;General Solution:&lt;/strong&gt; The OS uses the virtual memory system to provide application recovery as a service
&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Suspend each thread executing in the process and save its state. (Suspending threads is to avoid race conditions)&lt;/li&gt;
&lt;li&gt;Store a copy of the contents of the application memory on disk (this is the checkpoint)&lt;/li&gt;
&lt;li&gt;After a failure, resume execution by restoring the contents of memory from the checkpoint and resume each of the threads.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use address translation to minimize the amount of time the system is stalled during a checkpoint. We can mark the application pages as copy on write to do so.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Process Migration:&lt;/strong&gt; The ability to take a running program on one system, stop the execution, then resume it on a different machine.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;recoverable-virtual-memory&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#recoverable-virtual-memory&quot; aria-label=&quot;recoverable virtual memory permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Recoverable Virtual Memory&lt;/h2&gt;
&lt;p&gt;Unfortunately, checkpoint + restart is an expensive operation that we should use sparingly. Is it possible to provide the application the illusion of persistent memory, so that the contents are restored to a point not long before failure?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Take a checkpoint so that some consistent version of the application data is on disk&lt;/li&gt;
&lt;li&gt;Record a log of every update that the application makes to memory.&lt;/li&gt;
&lt;li&gt;Once things crash, read the checkpoint and apply the correct changes from the log.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; This is how text editors save their backups.
&lt;strong&gt;Cons:&lt;/strong&gt; Information that is not on the current version of the file can be leaked!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Incremental Checkpoint:&lt;/strong&gt; Created by stopping the program and saving a copy of any pages that have been modified since the previous checkpoint.&lt;/p&gt;
&lt;p&gt;How much work is lost during a crash is a function of how quickly we can write an incremental checkpoint to disk.&lt;/p&gt;
&lt;h2 id=&quot;deterministic-debugging&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#deterministic-debugging&quot; aria-label=&quot;deterministic debugging permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Deterministic Debugging&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Debugging a concurrent program is hard, we don’t control the scheduler, thus depending on how threads are scheduled program runs may vary.&lt;/li&gt;
&lt;li&gt;Debugging an OS is even harder, the OS uses widespread concurrency but also makes it difficult to tell input from output.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implementation:&lt;/strong&gt; Use a virtual machine abstraction to allow for debugging. The host kernel mediates the initial state, the input data from I/O devices, and precise timing of interrupts.&lt;/li&gt;
&lt;li&gt;For multicore systems, we also need to track the order in which threads go through critical sections in addition to the initial state, the input data from I/O devices, and precise timing of interrupts&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;security&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#security&quot; aria-label=&quot;security permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Security&lt;/h1&gt;
&lt;p&gt;The operating system needs to protect itself and other applications from malicious or buggy implementations.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Virtual Machine Honeypot:&lt;/strong&gt; Run the suspect application in a virtual machine constructed for the purpose of running suspect code. We can delete the virtual machine if the code is suspect.&lt;/p&gt;
&lt;h1 id=&quot;user-level-memory-management&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#user-level-memory-management&quot; aria-label=&quot;user level memory management permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;User Level Memory Management&lt;/h1&gt;
&lt;p&gt;Operating Systems now provide users the ability to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Decide where to get missing pages. (local disk, non-volatile memory, remote memory, etc.)&lt;/li&gt;
&lt;li&gt;Which pages can be accessed&lt;/li&gt;
&lt;li&gt;Which pages should be evicted.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;storage-devices&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#storage-devices&quot; aria-label=&quot;storage devices permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Storage Devices&lt;/h1&gt;
&lt;p&gt;Persistent Storage devices like SSDs or Magnetic Disks can hold much more memory but are much slower than DRAM.&lt;/p&gt;
&lt;h2 id=&quot;magnetic-disk&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#magnetic-disk&quot; aria-label=&quot;magnetic disk permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Magnetic Disk&lt;/h2&gt;
&lt;!-- ![Magnetic Disk](/media/10-Memory-Management/magneticdisk.JPG) --&gt;
&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Each disk drive holds one or more platters, which are the CD looking things that hold up the magnetic material. When the disk drive powers up, the platters are constantly spinning on the pole. The disk head reads/writes data by sensing or introducing a magnetic field on a surface. Since the platter is spinning very fast, it generates a layer of rapidly spinning air, which lets the disk head float close to the magnetic material without touching it. If the disk head does touch the material, this is known as a &lt;em&gt;disk crash&lt;/em&gt;. This can happen when you drop a running magnetic disk.&lt;/p&gt;
&lt;p&gt;The data itself is stored in 512 byte sectors, the disk drive must read and write the entire sector even if it only wants to change a single byte in the sector.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Track Buffering:&lt;/strong&gt; Improves performance by storing sectors that have been read by disk head but not yet requested by the OS.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write acceleration:&lt;/strong&gt; Stores data to be written to disk in the disk’s buffer memory and acknowledges the writes to the OS before the data is written to the platter. The data is actually written later. Of course, if power is lost before the disk’s buffer memory has been stored, then data might be lost.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tagged command queueing:&lt;/strong&gt; Issue multiple concurrent requests to disk and the disk processes the requests out of order in an optimal manner.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;access-and-performance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#access-and-performance&quot; aria-label=&quot;access and performance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Access and Performance&lt;/h3&gt;
&lt;p&gt;To go from a request to data, the disk must first seek the right track, wait for the desired sector to rotate to the head, then transfer the blocks. The equation for this is
&lt;code class=&quot;language-text&quot;&gt;disk access time = seek time + rotation time + transfer time&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Seek Time:&lt;/strong&gt; Move the arm over the desired track(each track is kind of like a different lane on a track in track and field). The &lt;strong&gt;minimum seek time&lt;/strong&gt; is the time it takes for the head to move from one track to an adjacent one. The &lt;strong&gt;maximum seek time&lt;/strong&gt; is the time it takes for a disk to move from the innermost track to the outermost track. The &lt;strong&gt;average seek time&lt;/strong&gt; is the average seek time across all possible pairs of tracks on a disk, this is usually approximated to the time it takes to seek a third of the way across a disk&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rotation Time:&lt;/strong&gt; After the disk head and found the correct track, it must wait for the target sector to rotate under it. The waiting time is known as the &lt;strong&gt;rotational latency&lt;/strong&gt;. However, most disks start reading the entire track’s sectors into their buffer memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transfer time:&lt;/strong&gt; After the disk head is on the target sector, the disk must transfer the data from the target sector to the buffer memory(for reads) or from the buffer memory to the target sector(for writes). Then, it transfers the buffer memory to main memory for reads or vice versa for writes. The &lt;strong&gt;surface transfer time&lt;/strong&gt; is the time to transfer one or more sequential sectors from a surface once the disk head begins reading. Thus, the &lt;strong&gt;surface transfer time&lt;/strong&gt; is usually faster for outer tracks than inner tracks since outer tracks have a higher linear velocity.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;flash-storage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#flash-storage&quot; aria-label=&quot;flash storage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Flash Storage&lt;/h2&gt;
&lt;p&gt;Flash storage is now used for laptops, machine room servers, phones, cameras, thumb drives, and everything in between. Flash storage is a type of &lt;strong&gt;solid state storage&lt;/strong&gt;, it has no moving parts and stores data using electrical circuits. It has much better random I/O, use less power, and is less vulnerable to physical damage.&lt;/p&gt;
&lt;!-- ![Solid State Drive Element](/media/10-Memory-Management/solid-state-drive.JPG) --&gt;
&lt;p&gt;Each flash storage element is a floating gate transistor. Since the floating gate is surrounded by an insulator, it can hold an electrical charge for months or years without requiring power. Even though it is not connected to anything, it can be charged or discharged via electron tunneling by running a sufficiently high-voltage current near it. Thus, the floating gate state can be detected by applying an intermediate voltage to the transistor control gate that will only be sufficient to activate the transistor if the floating gate is changed.&lt;/p&gt;
&lt;h3 id=&quot;access-and-performance-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#access-and-performance-1&quot; aria-label=&quot;access and performance 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Access and Performance&lt;/h3&gt;
&lt;p&gt;There are three operations we can perform on flash storage.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Erase erasure block:&lt;/strong&gt; Before flash memory can be written, it must be erased by setting each cell to a logical one. Flash memory can only be erased in large units known as erasure blocks. This is a slow operation, taking several milliseconds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write Page:&lt;/strong&gt; Once erased, NAND flash memory can be written on a page-by-page basis, where each page is typically 2048-4096 bytes. This takes tens of microseconds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Read Page:&lt;/strong&gt; NAND flash memory can be read on a page by page basis. Reading usually takes tens of microseconds.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;calculations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#calculations&quot; aria-label=&quot;calculations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Calculations&lt;/h2&gt;
&lt;p&gt;Without remapping&lt;br&gt;
&lt;code class=&quot;language-text&quot;&gt;Time per write = (sizeof erasure block / page size) * (page read time + page write time) + block erase time&lt;/code&gt;
With remapping
&lt;code class=&quot;language-text&quot;&gt;Time per write = block erase time / (sizeof erasure block / page size) + page write time&lt;/code&gt;
Remapping amortizes the cost of flashing an erasure block.&lt;/p&gt;
&lt;h3 id=&quot;durability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#durability&quot; aria-label=&quot;durability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Durability&lt;/h3&gt;
&lt;p&gt;Over time, the high current loads from flashing and writing memory causes the circuits to degrade. Eventually after a few thousand to few million erasures, a given cell will wear out and no longer reliably store a bit.&lt;/p&gt;
&lt;p&gt;Thus, flash devices use:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Error correcting codes:&lt;/strong&gt; Each page has some extra bytes to protect against bit errors in the page&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bad page and bad erasure block management:&lt;/strong&gt; If a page or erasure block has a manufacturing detect or wears out, the firmware marks it as bad and stops storing data on it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Wear leveling:&lt;/strong&gt; Rather than overwriting a page in flash, the flash translation layer remaps the logical page to a new physical page that has already been replaced. Thus, we wear out the flash device evenly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spare pages and erasure blocks:&lt;/strong&gt; Manufacturers may include spare pages and spare erasure blocks to provide extra space for wear leveling and to allow for bad page and bad erasure block management without shrinking the capacity of the storage device.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-future-for-memory-devices&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-future-for-memory-devices&quot; aria-label=&quot;the future for memory devices permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The future for memory devices&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Spinning disk vs flash storage:&lt;/strong&gt; Textbook is outdated, flash storage is almost always better&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Phase change memory:&lt;/strong&gt; Use a current to alter the state of glass between amorphous and crystalline forms which represents the data bit(0 or 1). Apparently it has better write performance and endurance than flash, though right now storage density isn’t that great.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memristor&lt;/strong&gt; A circuit element whose resistance depends on the amounts and directors of currents that have flowed through it in the past. The goal is for each core on a 32 core processor chip to have a few gigabytes of stacked memristor memory&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;</content:encoded></item><item><title><![CDATA[Caching]]></title><description><![CDATA[Notes on caching for operating systems]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/caching</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/caching</guid><pubDate>Fri, 22 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;examples-of-caches&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#examples-of-caches&quot; aria-label=&quot;examples of caches permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Examples of Caches&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;TLBs:&lt;/strong&gt; Caches recent results of address translation from page tables.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Virtually addressed caches:&lt;/strong&gt; Stores memory value associated with a virtual address&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Physically addressed caches:&lt;/strong&gt; This is a part of the virtually addressed cache. Each entry stores the memory value associated with a physical memory location.&lt;/li&gt;
&lt;li&gt;DNS caches, Web content caches, web search, email clients, incremental compilation, just in time translation, virtual memory, file systems, conditional branch prediction all use caches.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;design-challenges-of-caches&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#design-challenges-of-caches&quot; aria-label=&quot;design challenges of caches permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Design Challenges of Caches&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Locating the cached copy:&lt;/strong&gt; Check if the value you are looking for is in the cache&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Replacement Policy:&lt;/strong&gt; Which elements should be replaced when the cache is full?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Coherence:&lt;/strong&gt; What should we do when the cache is out of date?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;naive-cache-implementation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#naive-cache-implementation&quot; aria-label=&quot;naive cache implementation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Naive Cache Implementation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;An (address, value) pair stored in a map. When looking for something, we check if it exists in the map and return the value if it does(aka a cache hit). If it doesn’t this is a cache miss.&lt;/li&gt;
&lt;li&gt;The cost of retrieving data out of the cache must be less than fetching the data from memory. The likelihood of a cache hit must be high enough to be worth the effort.&lt;/li&gt;
&lt;li&gt;Two sources of predictability are temporal locality and spatial locality. Programs tend to reference the same instructions and data they recently referenced(Temporal Locality). Programs also tend to reference data that is near recently referenced data.&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;Latency(read request)=Prob(cache hit) × Latency(cache hit)+ Prob(cache miss) × Latency(cache miss)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write through cache:&lt;/strong&gt; All updates are sent immediately onward to memory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Write back cache:&lt;/strong&gt; Updates are stored in the cache and only sent to memory when the cache runs out of space.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;memory-hierarchy--when-to-use-caches&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#memory-hierarchy--when-to-use-caches&quot; aria-label=&quot;memory hierarchy  when to use caches permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Memory Hierarchy + When to use Caches&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Fundamental tradeoff: the smaller memory is, the faster it can be. The slower memory is, the cheaper it can be.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;working-sets&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#working-sets&quot; aria-label=&quot;working sets permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Working Sets&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A sufficiently large cache will have a high cache hit rate, since if you can fit all the memory and data, the miss rate will be 0.&lt;/li&gt;
&lt;li&gt;Most programs have an inflection point where a critical mass of program data can just barely fit inside the cache. This is known as a &lt;em&gt;working set&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Thrashing:&lt;/strong&gt; Occurs when a cache is too small to fit inside the working set.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;zipf-model&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#zipf-model&quot; aria-label=&quot;zipf model permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Zipf Model&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; New data is constantly being added to the web, it is likely that your cache is outdated when you request something from it. There is no working set for the web, a small amount of pages might be useful(gmail, facebook, youtube) but there is a huge amount of web pages that are only visited from time to time.&lt;/li&gt;
&lt;li&gt;Zipf can be described as
&lt;code class=&quot;language-text&quot;&gt;Frequency of visits to the kth most popular page ∝ 1 / kα&lt;/code&gt;
and can model the popularity of library books, the population of cities, salary distribution, number of facebook friends, etc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Heavy tailed distribution:&lt;/strong&gt; A significant number of references will be the most popular items, but a substantial portion will be less popular ones.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;cache-design&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cache-design&quot; aria-label=&quot;cache design permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cache Design&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fully associative:&lt;/strong&gt; Addresses can be stored anywhere in the cache, there is no ordering. When looking for an address, we check every entry in the cache: there is a cache hit if any of the entries match.
Cons: This is really slow as caches becomes bigger.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Direct mapped:&lt;/strong&gt; Each address is hashed then the data stored at the location of the hash.
Cons: If two different addresses hash to the same entry, the system will thrash.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Set associative:&lt;/strong&gt; The cache hashes the address to get a location, then checks the entry in each table in parallel. It returns the value if any entries match the address.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;replacement-policies&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#replacement-policies&quot; aria-label=&quot;replacement policies permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Replacement Policies&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; If we look up an address and find that it is a miss, how do we choose which memory block to replace?&lt;/p&gt;
&lt;h3 id=&quot;random&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#random&quot; aria-label=&quot;random permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Random&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How it works:&lt;/strong&gt; Choose a random block to replace.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Randomly evicting a block is fast, thus it is good for first-level hardware caches. Non-pessimal, randomness will never be the worst possible choice on average.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Unpredictable, it might counteract an application that tries to take advantage of the cache.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;first-in-first-outfifo&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#first-in-first-outfifo&quot; aria-label=&quot;first in first outfifo permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;First in First Out(FIFO)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How it works:&lt;/strong&gt; Evict the cache block or page that has been in memory the longest.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Each page spends an equal amount of time in the cache.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Imagine a program that cycles through an array, where the array is too large to fit into the cache. Then the cache is useless.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;optimal-cache-replacement-min&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#optimal-cache-replacement-min&quot; aria-label=&quot;optimal cache replacement min permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Optimal Cache Replacement (MIN)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How it works:&lt;/strong&gt; Replace whichever block that is used farthest in the future.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt; This is optimal. (aka the best possible algorithm)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Impossible, MIN requires knowledge of the future.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;least-recently-used-lru&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#least-recently-used-lru&quot; aria-label=&quot;least recently used lru permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Least Recently Used (LRU)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How it works:&lt;/strong&gt; Evict the block that has not been used for the longest period of time. In software, this is done with a linked list. In hardware, it is approximated with the clock algorithm&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Takes advantage of temporal locality&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Weak when the task is repeated scans through an array, the optimal strategy there is FIFO&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;least-frequently-usedlfu&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#least-frequently-usedlfu&quot; aria-label=&quot;least frequently usedlfu permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Least Frequently Used(LFU)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How it works:&lt;/strong&gt; Discard the page used least often&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Good in web caching. Ie just because we recently looked at spas in Iceland doesn’t mean we will frequently look at spas in Iceland. Frequency is a better approximation than time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; If an item is referenced repeatedly for a short period of time, this will stay in the cache long after it should have been evicted.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;beladys-anomaly&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#beladys-anomaly&quot; aria-label=&quot;beladys anomaly permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Belady’s Anomaly&lt;/h3&gt;
&lt;p&gt;Intuitively, adding space to a cache should always improve or maintain the cache hit rate. However, &lt;em&gt;Belady’s Anomaly&lt;/em&gt; says this isn’t the case.&lt;/p&gt;
&lt;p&gt;For some replacement policies like FIFO, adding more space will drastically change the contents of the cache, thus making the hit rate worse.&lt;/p&gt;
&lt;h2 id=&quot;memory-mapped-files&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#memory-mapped-files&quot; aria-label=&quot;memory mapped files permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Memory Mapped Files&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Demand Paging:&lt;/strong&gt; Applications can access more memory than is physically present on the machine by using memory pages as a cache for disk blocks.
&lt;strong&gt;Memory Mapped File:&lt;/strong&gt; The program directly accesses and modifies the contents of the file, treating memory as a write-back cache for disk.&lt;/p&gt;
&lt;h3 id=&quot;pros&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pros&quot; aria-label=&quot;pros permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pros&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Transparency:&lt;/strong&gt; The program can write directly into the file as if it was memory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zero copy I/O:&lt;/strong&gt; The OS does not need to copy file data from kernel buffers into user memory and back, it can just change the program’s page table entry to point to the physical page frame containing that part of the file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pipelining:&lt;/strong&gt; The program can operate on data in the file as soon as page tables are set up, no need to wait for the entire file to be read into memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interprocess communication:&lt;/strong&gt; Two processes can share memory via a memory mapped file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Large Files:&lt;/strong&gt; The only size limit of a memory mapped file is the size of the virtual address space.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;implementation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#implementation&quot; aria-label=&quot;implementation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Implementation&lt;/h3&gt;
&lt;p&gt;OS provides a system call where the kernel initializes a set of page table entries for that region of virtual address space, setting each entry to invalid.&lt;/p&gt;
&lt;p&gt;When the process gives an instruction that touches an invalid mapped address:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The TLB miss occurs, triggering a full page table lookup in hardware.&lt;/li&gt;
&lt;li&gt;The hardware finds the page table entry and finds that it is invalid, causing a &lt;em&gt;hardware page fault&lt;/em&gt; into the OS kernel.&lt;/li&gt;
&lt;li&gt;The OS kernel converts the address to a file offset.&lt;/li&gt;
&lt;li&gt;The OS kernel allocates an empty page frame and reads the required file block into the empty page frame.&lt;/li&gt;
&lt;li&gt;The disk interrupts the processor when the file block has been read and the scheduler resumes handling the page fault exception.&lt;/li&gt;
&lt;li&gt;The kernel updates the page table entry to point to the page frame allocated for the block and sets the entry to valid.&lt;/li&gt;
&lt;li&gt;The OS resumes execution of the process.&lt;/li&gt;
&lt;li&gt;The TLB misses, trigger a full page table lookup.&lt;/li&gt;
&lt;li&gt;The hardware returns the page frame to the processor, loads the TLB with the new translation, evicts the previous TLB entry, then uses the translation to construct a physical address.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To create the empty page frame that holds the incoming page from disk, the OS:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Selects a page to evict using the current replacement policy.&lt;/li&gt;
&lt;li&gt;Finds page table entries that point to the evicted page, usually through a core map.&lt;/li&gt;
&lt;li&gt;Set each page table entry to invalid, to prevent other processes from using the evicted page while it is being evicted.&lt;/li&gt;
&lt;li&gt;Copy back any changes to the evicted page.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;approximating-lru&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#approximating-lru&quot; aria-label=&quot;approximating lru permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Approximating LRU&lt;/h2&gt;
&lt;p&gt;Keeping a linked list to track when pages were last used in hardware is prohibitively expensive, thus, we will use the clock algorithm as an approximation instead.&lt;/p&gt;
&lt;h3 id=&quot;clock-algorithm&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#clock-algorithm&quot; aria-label=&quot;clock algorithm permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Clock algorithm&lt;/h3&gt;
&lt;p&gt;The OS scans through the core map of physical memory pages. 2. For each page frame, it records the value of the use bit and clears the use bit. 3. The OS does a shootdown for each page frame that has its use bit cleared.&lt;/p&gt;
&lt;p&gt;A common usage of the collected values of the use bit is the &lt;strong&gt;not recently used/kth chance algorithm&lt;/strong&gt; where the kernel picks a page that has not been set for the last k sweeps of the clock algorithm.&lt;/p&gt;
&lt;h2 id=&quot;virtual-memory&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#virtual-memory&quot; aria-label=&quot;virtual memory permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Virtual Memory&lt;/h2&gt;
&lt;p&gt;By backing every memory segment with a file on disk, we create virtual memory.&lt;/p&gt;
&lt;h3 id=&quot;self-paging&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#self-paging&quot; aria-label=&quot;self paging permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Self Paging&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; There is a malicious program that tries to grab as much memory as possible by using multiple threads to cycle through memory and add those pages.
&lt;strong&gt;Solution:&lt;/strong&gt; Self paging assigns every process its fair share of page frames. As the system starts to page, it evicts the page from whichever process has the most pages allocated to it.
&lt;strong&gt;Cons:&lt;/strong&gt; If there are two processes, one with a working set of 2/3 of memory and the other with 1/3 of memory, the ideal split is for the first process to get 2/3 of memory and the other to get 1/3 of memory. Unfortunately, self-paging will results in both process splitting the memory, causing the first process to thrash&lt;/p&gt;
&lt;h3 id=&quot;swapping&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#swapping&quot; aria-label=&quot;swapping permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Swapping&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Sometimes, there is simply too much data in all of the process’ working sets to effectively run them at once. If we try to run things normally, we will end up thrashing with every process.
&lt;strong&gt;Solution:&lt;/strong&gt; We can evict an entire process from memory (aka swapping)
&lt;strong&gt;Cons:&lt;/strong&gt; The process that just got evicted from memory will be sad :(&lt;/p&gt;
&lt;h1 id=&quot;future&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#future&quot; aria-label=&quot;future permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Future&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Low latency backing store:&lt;/strong&gt; Things that were once on hard disk are moving onto SSDs, things that are on SSDs will move onto even faster storage devices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Variable page sizes:&lt;/strong&gt; We will move toward smaller effective page sizes due to low latency solid state storage and cluster memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory aware applications:&lt;/strong&gt; Applications can be tuned to how much memory is in the first level cache to increase performance.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;How does set associative caches work?&lt;/li&gt;
&lt;li&gt;How does virtual memory work?&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Cross Validation and Regularization]]></title><description><![CDATA[Notes on Cross Validation and Regularization]]></description><link>https://albertsu.netlify.app//posts/datascience/cross-validation-and-regularization</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/datascience/cross-validation-and-regularization</guid><pubDate>Thu, 21 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;the-train-test-split&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-train-test-split&quot; aria-label=&quot;the train test split permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The train-test Split&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Training Data:&lt;/strong&gt; Used to fit model&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test Data:&lt;/strong&gt; Used to check generalization error&lt;/li&gt;
&lt;li&gt;How to split? Randomly, Temporally, Geographically (Usually Random)&lt;/li&gt;
&lt;li&gt;What size? Larger training set = more complex models, Larger test set = better estimate of generalization error (Usually 90%-10% or 75%-25%)&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;recipe-for-successful-generalization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#recipe-for-successful-generalization&quot; aria-label=&quot;recipe for successful generalization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Recipe for Successful Generalization&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;Split data into training(90%) and testing set(10%)&lt;/li&gt;
&lt;li&gt;Use only training data when training, use cross validation to test generalization(do not look at testing data!)&lt;/li&gt;
&lt;li&gt;Commit to the model and train once more using only training data&lt;/li&gt;
&lt;li&gt;Test the model using testing data. If accuracy is not acceptable, return to step 2&lt;/li&gt;
&lt;li&gt;Train on all available data and ship it&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;regularization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#regularization&quot; aria-label=&quot;regularization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Regularization&lt;/h1&gt;
&lt;p&gt;Parametrically controlling the model complexity
&lt;strong&gt;Naive Solution:&lt;/strong&gt; Find the best value of theta which uses less than B features. Unfortunately, this is an NP hard combinatorial search problem.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;L0 Norm Ball&lt;/strong&gt; Ideal for feature selection but combinatorically difficult to optimize&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;L1 Norm Ball&lt;/strong&gt; Encourages sparse solutions and is convex!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;L2 Norm Ball&lt;/strong&gt; Spreads weight over features(robust) and does not encourage sparsity&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;L1 + L2 Norm(Elastic Net)&lt;/strong&gt; Compromise, need to tune two regularization parameters&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Standardization:&lt;/strong&gt; Ensure each dimension has the same scale and is centered around 0
&lt;strong&gt;Intercept Terms:&lt;/strong&gt; Typically doesn’t regularize the intercept term &lt;/p&gt;
&lt;h1 id=&quot;ridge-regression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ridge-regression&quot; aria-label=&quot;ridge regression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Ridge Regression&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Model:&lt;/strong&gt; Y = X * theta
&lt;strong&gt;Loss:&lt;/strong&gt; Squared Loss
&lt;strong&gt;Regularization:&lt;/strong&gt; L2 regularization
&lt;strong&gt;Objective Function&lt;/strong&gt; Squared Loss + added penalty
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/6fa38369db8c6fcd6f756f1ac081badf/0c20b/RidgeRegression.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 22.916666666666668%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAFABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAMF/8QAFQEBAQAAAAAAAAAAAAAAAAAAAQL/2gAMAwEAAhADEAAAAd6RLUUf/8QAGBAAAgMAAAAAAAAAAAAAAAAAAAECETH/2gAIAQEAAQUCJuhZ/8QAFhEAAwAAAAAAAAAAAAAAAAAAAhAx/9oACAEDAQE/ARq//8QAFhEAAwAAAAAAAAAAAAAAAAAAARAx/9oACAECAQE/ATF//8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQAGPwJ//8QAGBAAAwEBAAAAAAAAAAAAAAAAAAERMWH/2gAIAQEAAT8hnWMmMwP/2gAMAwEAAgADAAAAEH/f/8QAFhEBAQEAAAAAAAAAAAAAAAAAAQAR/9oACAEDAQE/EBo2b//EABcRAAMBAAAAAAAAAAAAAAAAAAABESH/2gAIAQIBAT8QeYEf/8QAGxAAAgEFAAAAAAAAAAAAAAAAAREAITFBUXH/2gAIAQEAAT8QtRMOzZYFtysxyHP/2Q==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/6fa38369db8c6fcd6f756f1ac081badf/8ac56/RidgeRegression.webp 240w,
/static/6fa38369db8c6fcd6f756f1ac081badf/d3be9/RidgeRegression.webp 480w,
/static/6fa38369db8c6fcd6f756f1ac081badf/e46b2/RidgeRegression.webp 960w,
/static/6fa38369db8c6fcd6f756f1ac081badf/9012d/RidgeRegression.webp 992w&quot;
              sizes=&quot;(max-width: 960px) 100vw, 960px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/6fa38369db8c6fcd6f756f1ac081badf/09b79/RidgeRegression.jpg 240w,
/static/6fa38369db8c6fcd6f756f1ac081badf/7cc5e/RidgeRegression.jpg 480w,
/static/6fa38369db8c6fcd6f756f1ac081badf/6a068/RidgeRegression.jpg 960w,
/static/6fa38369db8c6fcd6f756f1ac081badf/0c20b/RidgeRegression.jpg 992w&quot;
            sizes=&quot;(max-width: 960px) 100vw, 960px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/6fa38369db8c6fcd6f756f1ac081badf/6a068/RidgeRegression.jpg&quot;
            alt=&quot;Ridge Regression&quot;
            title=&quot;Ridge Regression&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Note that there is always a unique optimal parameter vector for Ridge Regression!&lt;/p&gt;
&lt;h1 id=&quot;lasso-regression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lasso-regression&quot; aria-label=&quot;lasso regression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lasso Regression&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Model:&lt;/strong&gt; Y = X * theta
&lt;strong&gt;Loss:&lt;/strong&gt; Squared Loss
&lt;strong&gt;Regularization:&lt;/strong&gt; L2 regularization
&lt;strong&gt;Objective Function&lt;/strong&gt; Average Squared Loss + added penalty
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 854px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/b1459002d02fc9ee0e047aa5e319ef26/f537d/LassoRegression.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 34.583333333333336%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAHABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAEF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3oFB/8QAFhAAAwAAAAAAAAAAAAAAAAAAAAEQ/9oACAEBAAEFAoj/xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAUEAEAAAAAAAAAAAAAAAAAAAAQ/9oACAEBAAY/An//xAAZEAADAAMAAAAAAAAAAAAAAAAAARFRofD/2gAIAQEAAT8ha6keNiRH/9oADAMBAAIAAwAAABBzz//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8QP//EABsQAAICAwEAAAAAAAAAAAAAAAABESFRYaHB/9oACAEBAAE/EGNuukKBbZFB7J//2Q==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/b1459002d02fc9ee0e047aa5e319ef26/8ac56/LassoRegression.webp 240w,
/static/b1459002d02fc9ee0e047aa5e319ef26/d3be9/LassoRegression.webp 480w,
/static/b1459002d02fc9ee0e047aa5e319ef26/a7c35/LassoRegression.webp 854w&quot;
              sizes=&quot;(max-width: 854px) 100vw, 854px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/b1459002d02fc9ee0e047aa5e319ef26/09b79/LassoRegression.jpg 240w,
/static/b1459002d02fc9ee0e047aa5e319ef26/7cc5e/LassoRegression.jpg 480w,
/static/b1459002d02fc9ee0e047aa5e319ef26/f537d/LassoRegression.jpg 854w&quot;
            sizes=&quot;(max-width: 854px) 100vw, 854px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/b1459002d02fc9ee0e047aa5e319ef26/f537d/LassoRegression.jpg&quot;
            alt=&quot;Ridge Regression&quot;
            title=&quot;Ridge Regression&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Note that there is NO closed form solution for the optimal parameter vector for LASSO so we must use numerical methods like gradient descent&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/84f58b5f886fdbf5f4f61b15a2d75765/8351c/SummaryRegression.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 35%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAHABQDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAX/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAAG8AD//xAAUEAEAAAAAAAAAAAAAAAAAAAAQ/9oACAEBAAEFAn//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAUEAEAAAAAAAAAAAAAAAAAAAAQ/9oACAEBAAY/An//xAAUEAEAAAAAAAAAAAAAAAAAAAAQ/9oACAEBAAE/IX//2gAMAwEAAgADAAAAEAPP/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPxA//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPxA//8QAGRAAAwADAAAAAAAAAAAAAAAAAAEhEUFR/9oACAEBAAE/ENpDdwXp/9k=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/84f58b5f886fdbf5f4f61b15a2d75765/8ac56/SummaryRegression.webp 240w,
/static/84f58b5f886fdbf5f4f61b15a2d75765/d3be9/SummaryRegression.webp 480w,
/static/84f58b5f886fdbf5f4f61b15a2d75765/e46b2/SummaryRegression.webp 960w,
/static/84f58b5f886fdbf5f4f61b15a2d75765/a1214/SummaryRegression.webp 1254w&quot;
              sizes=&quot;(max-width: 960px) 100vw, 960px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/84f58b5f886fdbf5f4f61b15a2d75765/09b79/SummaryRegression.jpg 240w,
/static/84f58b5f886fdbf5f4f61b15a2d75765/7cc5e/SummaryRegression.jpg 480w,
/static/84f58b5f886fdbf5f4f61b15a2d75765/6a068/SummaryRegression.jpg 960w,
/static/84f58b5f886fdbf5f4f61b15a2d75765/8351c/SummaryRegression.jpg 1254w&quot;
            sizes=&quot;(max-width: 960px) 100vw, 960px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/84f58b5f886fdbf5f4f61b15a2d75765/6a068/SummaryRegression.jpg&quot;
            alt=&quot;Summary&quot;
            title=&quot;Summary&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;</content:encoded></item><item><title><![CDATA[Inference]]></title><description><![CDATA[Notes on Inference]]></description><link>https://albertsu.netlify.app//posts/datascience/inference</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/datascience/inference</guid><pubDate>Thu, 21 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;inference&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#inference&quot; aria-label=&quot;inference permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Inference&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Moving from premises to logical consequences&lt;/li&gt;
&lt;li&gt;Induction is inference from a particular premise to a universal conclusion&lt;/li&gt;
&lt;li&gt;Statistical inference: Using data analysis to deduce properties of underlying distribution&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;prediction-vs-inference&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#prediction-vs-inference&quot; aria-label=&quot;prediction vs inference permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Prediction vs Inference&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Prediction: Using our model to make predictions for unseen data. (Given attributes of house, how much is it worth?) We don’t care about how&lt;/li&gt;
&lt;li&gt;Inference: Using our model to draw conclusions about the underlying true relationships between our features and response. (How much extra will a house be worth if it has a view of the river?) We care about model parameters that are interpretable and meaningful&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;statistical-inference&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#statistical-inference&quot; aria-label=&quot;statistical inference permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Statistical Inference&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Draw conclusions about a population parameters given only a random sample&lt;/li&gt;
&lt;li&gt;Parameter: some function of population, ie population mean&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Estimator: some function of a sample, whose goal is to estimate a population parameter, ie sample mean. Estimators are random variables&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bias of an estimator: difference between estimator’s expected value and the true value of the parameter being estimated.&lt;/li&gt;
&lt;li&gt;Variance of an estimator: Expected squared deviation of an estimator from its mean&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;bootstrapping&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bootstrapping&quot; aria-label=&quot;bootstrapping permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bootstrapping&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Idea: treat our random sample as a population and resample from it&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Psuedocode&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;collect random sample of size n(aka bootstrap population)
initialize list of estimates
repeat 10,000 times:
    resample with replacement from bootstrap population
    apply estimator f to resample
    store in list
list of estimates is the bootstrapped sampling distribution of f&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;The median cannot be accurately drawn from bootstrapping&lt;/li&gt;
&lt;li&gt;If the sample is too small, bootstrapping won’t work&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;confidence-interval&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#confidence-interval&quot; aria-label=&quot;confidence interval permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Confidence Interval&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;What does a confidence interval p% mean?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If we take a sample from the population and compute P% confidence interval for the true population parameter, and repeat this many times, our population parameter will be in our interval P% of the time.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;to compute confidence interval(s,f,P), approximate sampling distribution of f using sample s. Choose middle P% of samples from this approximate distribution&lt;/li&gt;
&lt;li&gt;A 95% confidence interval does not mean that there is a 95% chance that the population parameter is in the interval, either the population parameter is in or isn’t&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;bootstrapping-model-parameters&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bootstrapping-model-parameters&quot; aria-label=&quot;bootstrapping model parameters permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bootstrapping Model Parameters&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Our estimate for theta depends on what our training data was.&lt;/li&gt;
&lt;li&gt;We want to think about all of the different ways that our training data and our parameter estimate could have come out&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We want to test whether a feature has any effect on the outcome. This works for linear and logistic regression models with any number of features.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;Estimate theta1 each time
Make confidence interval for theta 1 and see if 0 is in the interval
If yes, theta 1 is not significantly different than 0
If no, theta 1 is significantly different than 0&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;multicollinearity&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multicollinearity&quot; aria-label=&quot;multicollinearity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multicollinearity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;If features are related to one another, it might not be possible to have a change in one while holding the others constant&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Multicollinearity: Where a feature can be predicted fairly accurately by a lienar combination of other features.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Doesn’t impact model predictability, only interpretability&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Perfect Multicollinearity: one feature can be written exactly as linear combination of other features&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;summary&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary&quot; aria-label=&quot;summary permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Estimators are functions that provide estimates of true population parameters&lt;/li&gt;
&lt;li&gt;We can bootstrap to estimate the sampling distribution of an estimator&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using the bootstrapped sampling distribution, we can compute a confidence interval for our estimator&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This gives a rough idea of how uncertain we are about the true population parameter&lt;/li&gt;
&lt;li&gt;Only valid if the original random sample is representative&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The assumption when performing linear regression is that there is some true parameter theta that defines the linear relationship between features X and response Y&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We can use bootstrap to determine whether or not an individual feature is significant&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Multicollinearity arises when features are correlated with one another &lt;/li&gt;
&lt;li&gt;Supervised Learning = We have an X and Y&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Unsupervised Learning = We only have x, want to learn about X&lt;/p&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;
&lt;p&gt;What is confidence interval&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Logistic Regression]]></title><description><![CDATA[Notes on Logistic Regression]]></description><link>https://albertsu.netlify.app//posts/datascience/logistic-regression</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/datascience/logistic-regression</guid><pubDate>Thu, 21 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;linear-regression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#linear-regression&quot; aria-label=&quot;linear regression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Linear Regression&lt;/h2&gt;
&lt;p&gt;Goal: Predict a number from a set of features
Output: A real number
Process: determine optimal parameters by minimizing some average loss and something with a regularization penalty.&lt;/p&gt;
&lt;h2 id=&quot;classification&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#classification&quot; aria-label=&quot;classification permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Classification&lt;/h2&gt;
&lt;p&gt;Goal: Predict a categorical variable(ie win or lose, disease or no disease, spam or ham)
Types: Binary Classification(Two classes, ie spam or not spam), Multiclass classication(type of animal)&lt;/p&gt;
&lt;h2 id=&quot;logistic-regression-model&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#logistic-regression-model&quot; aria-label=&quot;logistic regression model permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Logistic Regression Model&lt;/h2&gt;
&lt;p&gt;P(Y=1|x) = 1 / (1 + e^((-x^t)_theta)) = sigma(x^T _ theta)
The probability of an observation belonging to class 1 given x(vector of features) = Linear regression function on linear transformation of a linear combination of x(vector of features)&lt;/p&gt;
&lt;p&gt;Thus, the logistic regression is sometimes known as a generalized linear model since it is a non-linear transformation of a linear model.&lt;/p&gt;
&lt;h2 id=&quot;pitfalls-of-squared-loss-functions-for-logitisic-regression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pitfalls-of-squared-loss-functions-for-logitisic-regression&quot; aria-label=&quot;pitfalls of squared loss functions for logitisic regression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pitfalls of Squared Loss functions for logitisic regression&lt;/h2&gt;
&lt;p&gt;Can get trapped in a flat region if the surface is not convex
Solution: Use Cross-entropy Loss!
Empirical Risk for logistic regression when using cross-entropy loss&lt;br&gt;
&lt;code class=&quot;language-text&quot;&gt;R(theta) = -(1/n)sum from i=1 to n( y_i * log(logistic regression(X_i^T * theta)) + (1 - y_i) * (1 - logistic regression(X_i^T * theta)))&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&quot;advantages-of-cross-entropy-loss&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#advantages-of-cross-entropy-loss&quot; aria-label=&quot;advantages of cross entropy loss permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Advantages of Cross-entropy loss&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Loss surface is guaranteed to be convex&lt;/li&gt;
&lt;li&gt;More strongly penalizes bad predictions&lt;/li&gt;
&lt;li&gt;Has roots in probability and information theory&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;logistic-regression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#logistic-regression&quot; aria-label=&quot;logistic regression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Logistic Regression&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Good for outliers since we wrap our data into a logistic function call&lt;/li&gt;
&lt;li&gt;L2 and L1 Loss Motivation: We want to measure the size of the error(difference between prediction and data), and for it to be indifferent to sign.&lt;/li&gt;
&lt;li&gt;To measure the difference between two probability distributions, the cross entropy loss is useful&lt;/li&gt;
&lt;li&gt;Use a threshold to classify a point on the logistic curve into a graph, this turns our decision rule into a classifier&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;evaluating-classifiers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#evaluating-classifiers&quot; aria-label=&quot;evaluating classifiers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Evaluating Classifiers&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The most basic evaluation for a classifier is accuracy. This is widely used, but in the presence of class imbalance it doesn’t mean much(since if we classify all the pictures as dog and dogs compose of 95% of the dataset our accuracy is 95%)&lt;/li&gt;
&lt;li&gt;Types of classification errors: True positive and True negatives(correct when classify observations as positive or negative), False positive(False alarm), False negative(We failed to detect)&lt;/li&gt;
&lt;li&gt;Confusion matrix: Gives us true + false positives and negatives for a given classifier&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;precision-and-recall&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#precision-and-recall&quot; aria-label=&quot;precision and recall permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Precision and Recall&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Accuracy = (True positive + True negative) / number of data points&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This tells us what proportion of points did our classifier classify correctly&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Precision = True positive / (True positive + False positive)&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Of all observations that were predicted to be 1, what proportion is actually 1? Penalized false positives&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Recall = True positive / (True positive + false negative)&lt;/code&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Of all observations that were actually 1, what proportion did we predict to be 1? Penalizes false negatives&lt;/li&gt;
&lt;li&gt;Can achieve 100% recall by making the classifier output 1 regardless of input, but makes precision low&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Generally, a higher classification threshold for positives equals fewer false positives, increases precision.&lt;/li&gt;
&lt;li&gt;On the other hand, a lower classification threshold has fewer false negatives, increases recall.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;visual-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#visual-metrics&quot; aria-label=&quot;visual metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Visual Metrics&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The only thing we can change after getting our model is to play around with our classification threshold&lt;/li&gt;
&lt;li&gt;Accuracy vs threshold: &lt;code class=&quot;language-text&quot;&gt;Threshold too high = false negatives&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;Threshold too low = false positives&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Precision vs threshold: &lt;code class=&quot;language-text&quot;&gt;Threshold increases = fewer false positives&lt;/code&gt;, precision tends to increase(not always)&lt;/li&gt;
&lt;li&gt;Recall vs threshold: &lt;code class=&quot;language-text&quot;&gt;Threshold increases = more false negatives&lt;/code&gt;, recall tends to decrease&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;other-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-metrics&quot; aria-label=&quot;other metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other Metrics&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;False Positive Rate = False Positives / (False Positives + True Negative)&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What proportion of innocent people did I convict&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;True Positive Rate = True Positives / (True Positives + False Negatives)&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What proportion of guilty people did I convict? aka recall&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;ROC Curve(Receiver Operating Characteristic): plots the false positive rate vs true positive rate&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;AUC(Area under curve): Area under ROC curve, best possible = 1, worst possible = 0.5(randomly guessing)&lt;/p&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;
&lt;/li&gt;
&lt;li&gt;Can a threshold be a sloped line os is this useless?&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Data 100 Variance]]></title><description><![CDATA[Notes on variance]]></description><link>https://albertsu.netlify.app//posts/datascience/variance</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/datascience/variance</guid><pubDate>Thu, 21 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Random Variable:&lt;/strong&gt; A numerical function of a random sample, a statistic.
&lt;strong&gt;Expectation:&lt;/strong&gt; Weighted average of the values of X, where the weights are the probabilities of the values
&lt;strong&gt;Variance:&lt;/strong&gt; Expected squared deviation from the expectation of X, the units of variances are the units of X squared.&lt;/p&gt;
&lt;h2 id=&quot;interpretation-of-variance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#interpretation-of-variance&quot; aria-label=&quot;interpretation of variance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Interpretation of Variance&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Var(X) = E[X^2] - (E[X])^2&lt;/li&gt;
&lt;li&gt;The main use of variance is to quantify chance error&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chebyshev’s inequality:&lt;/strong&gt; The vast majority of the probability is around the expectation plus minus a few standard deviations&lt;/li&gt;
&lt;li&gt;If X is centered, ie E[X] = 0, then Var(X) = E[X^2]&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;linear-transformations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#linear-transformations&quot; aria-label=&quot;linear transformations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Linear Transformations&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;E[aX + b] = aE[X] + b&lt;/li&gt;
&lt;li&gt;Var(aX+b)= a^2 * Var(X)&lt;/li&gt;
&lt;li&gt;SD(aX+b) = |a|SD(X)&lt;/li&gt;
&lt;li&gt;Var(aX+b)=Var(aX)&lt;/li&gt;
&lt;li&gt;A shift by b units does not affect spread&lt;/li&gt;
&lt;li&gt;The multiplication by a does affect spread&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;standardization-of-random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#standardization-of-random-variables&quot; aria-label=&quot;standardization of random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Standardization of random variables&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;X in standard units = (X-E[X]) / SD(X)&lt;/li&gt;
&lt;li&gt;X in standard units measures the number of SDs from expectation&lt;/li&gt;
&lt;li&gt;It is a linear transformation of X&lt;/li&gt;
&lt;li&gt;E[X_su] = 0, SD[X_su] = 1&lt;/li&gt;
&lt;li&gt;E[X_su^2] = Var[X_su] = 1&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;variance-of-a-sum---covariance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#variance-of-a-sum---covariance&quot; aria-label=&quot;variance of a sum   covariance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Variance of a sum -&gt; Covariance&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Var[X+Y] = Var[X] + Var[Y] + 2*Covariance&lt;/li&gt;
&lt;li&gt;Covariance = 2E[(x-E[X])(Y-E[Y])] =&lt;/li&gt;
&lt;li&gt;Covariance is 0 if X and Y are independent&lt;/li&gt;
&lt;li&gt;To get right of units for covariance, scale it by the standard deviation to get correlation&lt;/li&gt;
&lt;li&gt;Correlation = Cov[X,Y] / (SD[X] * SD[Y])&lt;/li&gt;
&lt;li&gt;Uncorrelated random variables is when covariance = 0&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;iid-sample-sum&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#iid-sample-sum&quot; aria-label=&quot;iid sample sum permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;I.I.D. sample sum&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;independent and identically distributed&lt;/li&gt;
&lt;li&gt;draws at random with replacement from a population are i.i.d.&lt;/li&gt;
&lt;li&gt;E[S_n] = n _ sample mean, Var[S_n]=n&lt;em&gt;(std dev)^2, SD[S&lt;/em&gt;n] = sqrt(n) * std dev&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;model-risk&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#model-risk&quot; aria-label=&quot;model risk permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Model Risk&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Mean squared error of prediction&lt;/li&gt;
&lt;li&gt;Model risk = E[(Y-Y(x))^2], Y(x) is a model that we are using&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chance Error:&lt;/strong&gt; Due to randomness alone in the new observations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bias:&lt;/strong&gt; Non random error due to model being different from the true underlying function&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;bias-and-overfitting&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bias-and-overfitting&quot; aria-label=&quot;bias and overfitting permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bias and Overfitting&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Overfitting: small differences in random samples which leads to large differences in the fitted model&lt;/li&gt;
&lt;li&gt;Overfitting solution: Reduce model complexity&lt;/li&gt;
&lt;li&gt;Model risk = std dev^2 + (model bias)^2 + model variance&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;</content:encoded></item><item><title><![CDATA[Address Translation]]></title><description><![CDATA[Notes on the different types of real-time scheduling systems]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/address-translation</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/address-translation</guid><pubDate>Tue, 12 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Address Translation allows for process isolation, interprocess communication(via sharing a common memory region)&lt;/li&gt;
&lt;li&gt;Shared code segments(ie sharing a library between programs)&lt;/li&gt;
&lt;li&gt;Program initialization(starting program before all code is loaded from memory to disk)&lt;/li&gt;
&lt;li&gt;Efficient dynamic memory allocation (only allocate memory for what is needed)&lt;/li&gt;
&lt;li&gt;Cache management (change how programs are positioned in physical memory to improve cache efficiency)&lt;/li&gt;
&lt;li&gt;Program Debugging (address translation prevents the rewriting of the code section, making things easier to debug)&lt;/li&gt;
&lt;li&gt;Efficient I/O (allows data to be safely transferred between user mode apps and I/O devices)&lt;/li&gt;
&lt;li&gt;Memory Mapped Files (map files into address space so contents of files can be referenced with program instructions)&lt;/li&gt;
&lt;li&gt;Virtual memory (fool the application into thinking that there is more memory than is physically present on computer)&lt;/li&gt;
&lt;li&gt;Checkpointing + Restarting (Can restart program from the saved state)&lt;/li&gt;
&lt;li&gt;Persistent Data Structures (Region of memory that survives program + system crashes)&lt;/li&gt;
&lt;li&gt;Process Migration (can move executing program from on server to another, ie load balancing)&lt;/li&gt;
&lt;li&gt;Distributed Storage (Turn network of servers into shared memory using address translation)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;possible-places-to-put-address-translation-implementation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#possible-places-to-put-address-translation-implementation&quot; aria-label=&quot;possible places to put address translation implementation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Possible Places to put address translation implementation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Specialized hardware in system&lt;/li&gt;
&lt;li&gt;trusted compiler, linker, or byte-code interpreter&lt;/li&gt;
&lt;li&gt;application translates pointers&lt;/li&gt;
&lt;li&gt;hybrid, with address translations in software and hardware&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;simple-address-translation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#simple-address-translation&quot; aria-label=&quot;simple address translation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Simple Address Translation&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;At its core, it is a black box that translates a virtual address to a physical address&lt;/li&gt;
&lt;li&gt;Possible implementations could be an array, a tree, a hash table, or pretty much anything&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Goals of an address translation black box:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Memory Protection -&lt;/strong&gt; Limit access of a process to certain regions of memory(ie code)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory Sharing -&lt;/strong&gt; Allow multiple processes to share memory (ie program code, file)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexible Memory placement -&lt;/strong&gt; Put process anywhere to pack physical memory + use caches better&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sparse Addresses -&lt;/strong&gt; Programs have multiple dynamic memory regions such as the heap for data objects, a stack for each thread, and memory mapped files&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Runtime lookup efficiency -&lt;/strong&gt; Fetching addresses should be fast&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compact Translation Table -&lt;/strong&gt; Black box should not take much memory&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Portability -&lt;/strong&gt; Works on all types of architectures&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;symbol-table-and-dynamically-linked-librarydll&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#symbol-table-and-dynamically-linked-librarydll&quot; aria-label=&quot;symbol table and dynamically linked librarydll permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Symbol Table and Dynamically Linked Library(DLL)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Multiprogramming requires address translation for absolute addresses, such as goto the start of the procedure or loading a global variable.&lt;/li&gt;
&lt;li&gt;Old Solution: Early OS used relocating loaders, after picking an empty region of physical memory, the loader would modify instructions that used an absolute addresses. The modifications were tracked in the &lt;em&gt;symbol table&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Current Solution: Generate the symbol table, which tracks which values need to be modified when files are assembled together by the linker. Also, commercial operating systems use a dynamically linked library, which links a library into a program when the program first calls into the library.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;flexible-address-translation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#flexible-address-translation&quot; aria-label=&quot;flexible address translation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Flexible Address Translation&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;The simplest model of memory management is base + bound. Each process has a base and bound to put everything between.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;segments&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#segments&quot; aria-label=&quot;segments permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Segments&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Segmentation:&lt;/strong&gt; Instead of keeping only one pair of base and bound, we can instead keep an array of base and bounds.&lt;/li&gt;
&lt;li&gt;Segments are contiguous in memory, however, the different segments are not contiguous to each other, this would defeat the point. There will likely be gaps in the segments.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;segmentation fault&lt;/strong&gt; is a failure to a part of memory outside the legal segments.&lt;/li&gt;
&lt;li&gt;Segments are powerful, they are used in x86 and allows two processes to share code as their two segment tables point to the same base and bounds for their segments. They can also be used to share library routines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fork:&lt;/strong&gt; Makes a copy of the parent’s segment table then copy the data there.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zero on reference:&lt;/strong&gt; The operating system allocates memory for the heap but only zeroes out the first few kb of the segment. It then sets a bound register to limit the program to the zeroed part of memory. If the program wants more memory, the OS will zero out existing memory before resuming execution.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; There is a large overhead for managing the large number of variable size memory segments. Also, external fragmentation can occur where the small chunks between the segments have enough free space for a new application but the free space is not contiguous.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Questions left:&lt;/strong&gt; How much memory should we allocate per segment?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;paged-segments&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#paged-segments&quot; aria-label=&quot;paged segments permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Paged Segments&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Paged Memory:&lt;/strong&gt; Memory that is allocated in fixed sized chunks called page frames.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Page Table:&lt;/strong&gt; Similar to segment table,its entries contain pointers to page frames. No need for a bound since all page sizes are the same.&lt;/li&gt;
&lt;li&gt;To share memory between processes, we set the page table entry for each process sharing a page to point to the same physical page frame using a &lt;strong&gt;core map&lt;/strong&gt; - a data structure that tracks info about each physical page frame such as which page table entries point to it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data breakpoint:&lt;/strong&gt; request to stop the execution of a program when it references or modifies a memory location. It is implemented by making that location read only, so that every change can check if the instruction causing the write on read-only memory exception is the breakpoint.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; While physical memory management is easier, virtual address space becomes more challenging since compilers expect the stack to be contiguous(for virtual addresses) and of arbitrary size.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Questions:&lt;/strong&gt; How big should a page frame be? A larger page frame wastes space if not all memory inside frame is used. A small page frame means there are tons of page frames, meaning that the page table is very large.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;multi-level-translation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multi-level-translation&quot; aria-label=&quot;multi level translation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multi Level Translation&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Instead of using an array for lookup, we can use a tree instead for the following reasons.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficient Memory Allocation:&lt;/strong&gt; Use a bitmap to store free space&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficient Disk Transfers:&lt;/strong&gt; Hardware disks are partitioned into fixed size regions known as &lt;em&gt;sectors&lt;/em&gt;, we can make page size a multiple of the &lt;em&gt;sector&lt;/em&gt; to simplify transfers, loading, reading, and writing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficient Lookup:&lt;/strong&gt; Use a &lt;em&gt;translation lookaside buffer&lt;/em&gt; to make lookups fast&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficient Reverse Lookup:&lt;/strong&gt; Easy to go from physical page frame to set of virtual addresses. This is crucial for the infinite virtual memory illusion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Page protection and sharing granularity:&lt;/strong&gt; Each page table entry has its own access permissions&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;paged-segmentation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#paged-segmentation&quot; aria-label=&quot;paged segmentation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Paged Segmentation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Only two levels in the tree.&lt;/li&gt;
&lt;li&gt;Each segment table entry points to a page table, which points to the memory backing that segment.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 652px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/f4b18c3f389b5a4549603a10e5d5ac75/a6d32/PagedSegmentation.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 95.83333333333334%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAATABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAEDAgX/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAAH3oh2DOBqD/8QAFxAAAwEAAAAAAAAAAAAAAAAAABARAf/aAAgBAQABBQIq1wi//8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAwEBPwEf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPwEf/8QAFhAAAwAAAAAAAAAAAAAAAAAAECAx/9oACAEBAAY/AjW//8QAGhAAAgMBAQAAAAAAAAAAAAAAAAEQESExUf/aAAgBAQABPyHTSahg69UNLKHD/9oADAMBAAIAAwAAABCjxzz/xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAEDAQE/EB//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAECAQE/EB//xAAdEAEAAwABBQAAAAAAAAAAAAABABEhMUFRcYGh/9oACAEBAAE/EGlpvmUcq66MOIDwD2QWUUqguGhUQs5e8Mc+wAAYE//Z&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/f4b18c3f389b5a4549603a10e5d5ac75/8ac56/PagedSegmentation.webp 240w,
/static/f4b18c3f389b5a4549603a10e5d5ac75/d3be9/PagedSegmentation.webp 480w,
/static/f4b18c3f389b5a4549603a10e5d5ac75/db2ac/PagedSegmentation.webp 652w&quot;
              sizes=&quot;(max-width: 652px) 100vw, 652px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/f4b18c3f389b5a4549603a10e5d5ac75/09b79/PagedSegmentation.jpg 240w,
/static/f4b18c3f389b5a4549603a10e5d5ac75/7cc5e/PagedSegmentation.jpg 480w,
/static/f4b18c3f389b5a4549603a10e5d5ac75/a6d32/PagedSegmentation.jpg 652w&quot;
            sizes=&quot;(max-width: 652px) 100vw, 652px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/f4b18c3f389b5a4549603a10e5d5ac75/a6d32/PagedSegmentation.jpg&quot;
            alt=&quot;Paged Segmentation&quot;
            title=&quot;Paged Segmentation&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;h3 id=&quot;multi-level-paged-segmentation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multi-level-paged-segmentation&quot; aria-label=&quot;multi level paged segmentation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multi Level Paged Segmentation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Use a &lt;em&gt;Global Descriptor Table&lt;/em&gt;, aka a segment table.&lt;/li&gt;
&lt;li&gt;For 32 bit systems, First 10 bits-page directory, Second 10 bits-second level page table, final 12 bits-offset within a page&lt;/li&gt;
&lt;li&gt;For 64 bit systems, only the first 48 bits are used&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;portability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#portability&quot; aria-label=&quot;portability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Portability&lt;/h1&gt;
&lt;h2 id=&quot;motivation-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation-1&quot; aria-label=&quot;motivation 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h2&gt;
&lt;p&gt;Main memory density is increasing by almost a bit per year, for a multi-level page table to map all of memory, an extra level of the page table is needed every decade to keep up with main memory size.&lt;/p&gt;
&lt;p&gt;For things like copy-on-write, zero-on-reference, fill-on-reference, we need a different view for hardware and virtual address space.&lt;/p&gt;
&lt;p&gt;We also need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;List of memory objects:&lt;/strong&gt; We need to known which memory region represents program code, library code, shared data, copy-on-write, or memory-mapped file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Virtual to physical translation:&lt;/strong&gt; In exceptions and system call parameter copying, the kernel needs to translate virtual to physical addresses to check if invalid page is truly invalid. (it could be just not yet loaded or doing some copy-on-write magic)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Physical to virtual translation:&lt;/strong&gt; The core map. Which processes map to a specific physical memory location so that when the kernel updates a page status, it also updates every page table entry that refers to that page.&lt;/li&gt;
&lt;li&gt;OSX uses a hash table rather than a tree for software translation data. This hash table is known as an inverted hash table&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;inverted page table entry = {
  process or memory object ID,
  virtual page number,
  physical page frame number,
  access permissions
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1 id=&quot;efficient-address-translation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#efficient-address-translation&quot; aria-label=&quot;efficient address translation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Efficient Address Translation&lt;/h1&gt;
&lt;h2 id=&quot;motivation-2&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation-2&quot; aria-label=&quot;motivation 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h2&gt;
&lt;p&gt;Page tables, Segmentations, etc. all require multiple extra memory references before reaching the physical memory location. This greatly increases the overhead per instruction.&lt;/p&gt;
&lt;p&gt;Thus, we can use a cache to improve performance. A cache stores certain data to increase the speed of future requests, usually by taking advantage of temporal locality or spatial locality.&lt;/p&gt;
&lt;h2 id=&quot;translation-lookaside-buffer-tlb&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#translation-lookaside-buffer-tlb&quot; aria-label=&quot;translation lookaside buffer tlb permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Translation Lookaside Buffer (TLB)&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Instructions are usually next to each other both in virtual memory and physical memory, it would be pointless to load instructions one at a time from physical memory since they are on the same page in physical memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TLB:&lt;/strong&gt; A small hardware table that contains results of a recent address translation. Each entry maps a virtual page to a physical page.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;TLB entry = {
          virtual page number,
          physical page frame number,
          access permissions
            }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;On a lookup, the TLB hardware checks all of the entries against the virtual page. If there is a match, the TLB returns the physical address. (TLB hit) If none of the entries match, the hardware does the full address translation and is added to the TLB, usually replacing the least recently used entry.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 576px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/605521493baf4ffe6d1f8ef341be6a11/ac097/TLBhardwarepagetable.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 74.16666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAECBf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhADEAAAAe9LDQP/xAAXEAEAAwAAAAAAAAAAAAAAAAAQABEh/9oACAEBAAEFAm5h/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQAGPwJf/8QAGRAAAgMBAAAAAAAAAAAAAAAAAAEQEWGB/9oACAEBAAE/IWtOxQto/9oADAMBAAIAAwAAABDTz//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8QP//EABoQAQADAQEBAAAAAAAAAAAAAAEAETEhQZH/2gAIAQEAAT8QRbsQ5Tn22Gbc6bHRXyCJZk//2Q==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/605521493baf4ffe6d1f8ef341be6a11/8ac56/TLBhardwarepagetable.webp 240w,
/static/605521493baf4ffe6d1f8ef341be6a11/d3be9/TLBhardwarepagetable.webp 480w,
/static/605521493baf4ffe6d1f8ef341be6a11/6264f/TLBhardwarepagetable.webp 576w&quot;
              sizes=&quot;(max-width: 576px) 100vw, 576px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/605521493baf4ffe6d1f8ef341be6a11/09b79/TLBhardwarepagetable.jpg 240w,
/static/605521493baf4ffe6d1f8ef341be6a11/7cc5e/TLBhardwarepagetable.jpg 480w,
/static/605521493baf4ffe6d1f8ef341be6a11/ac097/TLBhardwarepagetable.jpg 576w&quot;
            sizes=&quot;(max-width: 576px) 100vw, 576px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/605521493baf4ffe6d1f8ef341be6a11/ac097/TLBhardwarepagetable.jpg&quot;
            alt=&quot;Paged Segmentation&quot;
            title=&quot;Paged Segmentation&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The cost for a TLB lookup is&lt;br&gt;
&lt;code class=&quot;language-text&quot;&gt;Cost (address translation) = Cost (TLB lookup) + Cost (full translation) × (1 - P(hit))&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;superpages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#superpages&quot; aria-label=&quot;superpages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Superpages&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Superpage:&lt;/strong&gt; Set of contiguous pages in physical memory that map to the same contiguous region in virtual memory. For example, two 4 Kb pages that are next to each other form an 8 Kb superpage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Reduces the number of TLB entries needed since one superpage can map many pages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Complicates the OS by requiring the system to allocate chunks of memory in different sizes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implementation:&lt;/strong&gt; Each entry in the TLB has a flag signifying whether the entry is a page or superpage. When matching against a superpage, the TLB ignores the offset within a superpage and only considers the most significant bits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Uses:&lt;/strong&gt; When the computer display is being withdrawn, a normal TLB isn’t big enough to hold all the entries. Large Matrices in scientific code can be sped up via superpages.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;tlb-consistency-issues&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tlb-consistency-issues&quot; aria-label=&quot;tlb consistency issues permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;TLB Consistency Issues&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Process context switch:&lt;/strong&gt; The virtual addresses of the old process are no longer valid. Otherwise, the new process would be reading the old process’ data structures, causing it to crash or even worse, reading sensitive info such as passwords stored in memory.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We need to get rid of the TLB’s copies of the old process’ page translations and permission. We can flush the TLB(discard all contents), or flush the tagged TLB, where entries contain the process ID that produced each translation.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;tagged TLB entry = {
  process ID,
  virtual page number,
  physical page frame number,
  access permissions
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;&lt;strong&gt;Permission Reduction:&lt;/strong&gt; When the OS modifies an entry in a page table, the special purpose hardware keeps the cached data consistent. Software is needed so a single modification can affect multiple TLB entries and the OS ensures the TLB does not contain an incorrect mapping.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When adding permissions to virtual address space, the TLB can be left alone.
When reducing permissions to a page, the kernel checks if the TLB has a copy of the old page. If it does, the kernel must update permissions.&lt;/p&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;&lt;strong&gt;TLB Shootdown:&lt;/strong&gt; Multiprocessors might have a cached copy of a translation in its TLB. Thus, whenever a page table entry is modified, the corresponding entry in every processor’s TLB must be discarded. This requires interrupting the processor. (very expensive!)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;virtually-addressed-caches&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#virtually-addressed-caches&quot; aria-label=&quot;virtually addressed caches permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Virtually Addressed Caches&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Stores a copy of the contents of physical memory, indexed by the virtual address.&lt;/li&gt;
&lt;li&gt;On modern processors, these are split up located near the processor core, one for instruction lookups and one for data.&lt;/li&gt;
&lt;li&gt;Process context switch, permission reduction, and shootdown are all issues with virtually addressed caches.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory address alias:&lt;/strong&gt; Different processes have different virtual addresses that point to the same memory location. Each process has its own TLB entry for that memory, and the virtual cache stores a copy of the memory for each process. However, when a process modifies its own copy, how does the system know to update the other copy?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The solution is to store the physical address with the virtual address in the virtual cache.&lt;/p&gt;
&lt;h2 id=&quot;physically-addressed-caches&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#physically-addressed-caches&quot; aria-label=&quot;physically addressed caches permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Physically Addressed Caches&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Consulted as a second level cache after the virtually addressed cache and the TLB but before main memory.&lt;/li&gt;
&lt;li&gt;Once the physical address of the memory address is located, we look at the Physically Address cache to see if there is a match. Thus we can avoid going to main memory&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;software-protection&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#software-protection&quot; aria-label=&quot;software protection permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Software Protection&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Naive software only protection: A machine code interpreter implemented in software simulates each instruction and only runs it if the addresses in the page table are permitted. (this is extremely slow!)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Goals of software protection:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Simplify Hardware:&lt;/strong&gt; Is it possible to have eliminate hardware address translation to limit hardware complexity and runtime overhead from computers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application level protection:&lt;/strong&gt; A browser wants to protect itself and the OS from malicious code in applications it runs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Protection inside the kernel:&lt;/strong&gt; Running third party code inside the kernel is dangerous, we need to protect the code in software.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Portable Security:&lt;/strong&gt; Protection as a part of the runtime system allows us to download and run different applications without feat that the application will corrupt the OS.&lt;/li&gt;
&lt;li&gt;Thus, we want a &lt;em&gt;sandbox&lt;/em&gt; to execute untrusted code so that it can work without harming the rest of the system.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;single-language-os&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#single-language-os&quot; aria-label=&quot;single language os permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Single Language OS&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Restrict all applications to be written in a single, carefully designed programming language(like solidity -&gt; EVM?)&lt;/li&gt;
&lt;li&gt;For example, Javascript in modern web browsers is sandboxed. If a JavaScript program attempts to call a procedure that does not exist or reference arbitrary memory locations, the interpreter causes a runtime exception and stop the program.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Using a single language based software protection relies on trusting the interpreter. Since interpreted code is slow, many interpreted systems put their functionality into system libraries that are compiled into machine code and run directly on the processor. A JavaScript program could cause a library routine to overwrite the end of a buffer for a buffer overflow attack.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thus, many systems use both software and hardware protection.&lt;/p&gt;
&lt;h2 id=&quot;language-independent-software-fault-isolation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#language-independent-software-fault-isolation&quot; aria-label=&quot;language independent software fault isolation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Language Independent Software Fault Isolation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Motivation:&lt;/strong&gt; Single Language OS requires trusting every compiler for every possible language. Is there a way we can isolate application code in a language independent fashion without using hardware?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implementation:&lt;/strong&gt; Use a base + bound method. First, insert machine instructions into executable and check that each address is in base + bound. Second, use control + data flow analysis to remove checks that are not strictly necessary for the sandbox to be correct.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;checking-that-each-address-is-in-base--bound&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#checking-that-each-address-is-in-base--bound&quot; aria-label=&quot;checking that each address is in base  bound permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Checking that each address is in base + bound&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;For store + load instructions, just check to make sure that the addresses are within the correct region of data.&lt;/li&gt;
&lt;li&gt;For indirect branch instructions, make sure the program cannot branch outside of the sandbox except for predefined entry + exit points.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;control--data-flow-analysis&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#control--data-flow-analysis&quot; aria-label=&quot;control  data flow analysis permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Control + Data flow analysis&lt;/h3&gt;
&lt;p&gt;This allows us to eliminate extra inserted instructions if they are not needed. Possible optimizations include:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Loop invariants:&lt;/strong&gt; If a loop strides through memory, we can use math to ensure all memory accesses in loop will be in the protected region.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Return Values:&lt;/strong&gt; If static analysis can prove a procedure does not modify the return program counter on the stack, the return can be made safely.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cross procedure checks:&lt;/strong&gt; If code analysis can prove a parameter is always checked before it is passed as an argument to a subroutine, it does not need to be checked inside the subroutine.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;sandboxes-via-intermediate-code&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sandboxes-via-intermediate-code&quot; aria-label=&quot;sandboxes via intermediate code permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sandboxes via intermediate code&lt;/h3&gt;
&lt;p&gt;Instead of creating a sandbox for x86 or ARM code, we can check a form of intermediate code and run that into the sandbox(kind of like a virtual machine)&lt;/p&gt;
&lt;p&gt;For example, the JVM can be used to safely contain java code.&lt;/p&gt;
&lt;h1 id=&quot;future&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#future&quot; aria-label=&quot;future permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Future&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Very large memory systems:&lt;/strong&gt; Ever increasing memories will require larger TLBs to hide the depth of the lookup trees.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multiprocessors:&lt;/strong&gt; TLB consistency will be more and more expensive as more processors will be added.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;User level sandboxes:&lt;/strong&gt; Each application has its own sandbox which is enforced in hardware.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;</content:encoded></item><item><title><![CDATA[Queueing Theory]]></title><description><![CDATA[Notes on Queueing Theory]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/queueing-theory</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/queueing-theory</guid><pubDate>Tue, 12 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;queueing-theory&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#queueing-theory&quot; aria-label=&quot;queueing theory permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Queueing Theory&lt;/h1&gt;
&lt;p&gt;Response time depends non-linearly on the rate that tasks arrive at a system. For all intents and purposes, we assume that the system is work-conserving(all tasks that arrive are eventually serviced). Secondly, we are using FIFO scheduling.&lt;/p&gt;
&lt;h1 id=&quot;definitions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#definitions&quot; aria-label=&quot;definitions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Definitions&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Server:&lt;/strong&gt; A server is anything that performs tasks. ie web server, processor in a client machine, cashier in supermarket&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Queueing delay(W):&lt;/strong&gt; The total time a task must wait to be scheduled. aka wait time&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Number of tasks queued(Q):&lt;/strong&gt; number of tasks on the queue&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service time(S):&lt;/strong&gt; The time to complete a task assuming no waiting. aka execution time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Response time(R):&lt;/strong&gt; Queueing delay(W) + Service time(S)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Arrival rate(lambda):&lt;/strong&gt; Average rate at which new tasks arrive&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Arrival process:&lt;/strong&gt; When tasks arrive and whether arrivals are bursty or spread evenly over time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service Rate(u):&lt;/strong&gt; Number of tasks the server can complete per unit time when there is work to do.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Utilization(U):&lt;/strong&gt; Fraction of time the server is busy. &lt;code class=&quot;language-text&quot;&gt;U = lambda / u&lt;/code&gt; if lambda &amp;#x3C; u, else &lt;code class=&quot;language-text&quot;&gt;U = 1&lt;/code&gt; if lambda &gt;= u&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Throughput(X):&lt;/strong&gt; Number of tasks processed by the system per unit of time. &lt;code class=&quot;language-text&quot;&gt;X = U * u&lt;/code&gt; We can rewrite this as &lt;code class=&quot;language-text&quot;&gt;X = lambda if U &amp;lt; 1, else X = u if U=1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Number of tasks in the system(N):&lt;/strong&gt; The number queued + number receiving service. &lt;code class=&quot;language-text&quot;&gt;N = Q + U&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;littles-law&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#littles-law&quot; aria-label=&quot;littles law permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Little’s Law&lt;/h1&gt;
&lt;p&gt;Conditions: Applies to any stable system where the arrival rate matches the departure rate. It relates the average throughput, response time, and number of tasks in the system.
&lt;code class=&quot;language-text&quot;&gt;N = X * R&lt;/code&gt;&lt;/p&gt;
&lt;h1 id=&quot;response-time-vs-utilization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#response-time-vs-utilization&quot; aria-label=&quot;response time vs utilization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Response Time vs Utilization&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Higher Utilization normally implies higher queueing delay and higher response times.&lt;/li&gt;
&lt;li&gt;Higher Utilization also increases the risk of overload(where requests grow faster than they can be processed, thus queues and wait times grow without bound)&lt;/li&gt;
&lt;li&gt;Can predict average response time from the arrival process and service time but it is difficult&lt;/li&gt;
&lt;li&gt;Goal: make tradeoffs between higher utilization and better response time. In the fast, higher utilization was favored since computers were expensive, now, it is better to have a better response time since computers are cheaper than humans.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Best case(Evenly spaced arrivals):&lt;/strong&gt; Suppose we have a set of fixed sized tasks that arrive equally spaced from one another. As long as the rate at which tasks arrive is less than the rate at which the server completes the tasks, there is no queueing since the server finishes the previous request just in time for the next arrival.&lt;/li&gt;
&lt;li&gt;Suppose arrivals come in every 1 ms and the server can process each task in 1ms. If at some point a single extra request arrives, every other request will need to wait 1ms for that request.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Worst case(Bursty arrivals):&lt;/strong&gt; Suppose a group of tasks arrive exactly at the same time. The average wait time increases linearly as more tasks arrive together. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exponential arrivals:&lt;/strong&gt; A useful model for understanding queueing behavior is the exponential distribution. This can describe the time between tasks arriving and the time it takes to service each task.
An exponential distribution of a continuous random variable with a mean of 1 / lambda has the probability density function `f(x) = lambda * e ^ -(lambda * x)
The exponential distribution is &lt;em&gt;memoryless&lt;/em&gt;, ie no matter how long we have already waited for the event, the likelihood of that event occurring remains the same.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;what-if-questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-if-questions&quot; aria-label=&quot;what if questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What if Questions&lt;/h1&gt;
&lt;h2 id=&quot;what-if-we-changed-the-scheduling-policy-from-fifo-to-something-else&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-if-we-changed-the-scheduling-policy-from-fifo-to-something-else&quot; aria-label=&quot;what if we changed the scheduling policy from fifo to something else permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What if we changed the scheduling policy from FIFO to something else?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;If the distribution of arrivals or service times is less bursty than an exponential(ie evenly spaced or Gaussian), FIFO will deliver nearly optimal response times. Round robin will be worse than FIFO&lt;/li&gt;
&lt;li&gt;If task service times are exponentially distributed but individual task times are unpredictable, the average response time is exactly the same for Round Robin as for FIFO.&lt;/li&gt;
&lt;li&gt;If task lengths can be predicted and there is variability in service times, Shortest Job first can improve average response times, particularly if arrivals are bursty&lt;/li&gt;
&lt;li&gt;Real world systems usually have more bursty arrival times than the exponential distribution, their distributions are known as &lt;em&gt;heavy tailed distributions&lt;/em&gt; since it has more long tasks. SJF is better than Round Robin which is better than FIFO for &lt;em&gt;heavy tailed distributions&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;SJF can improve average response times but increases response times for long tasks since long tasks will only complete immediately before an idle period. As utilization increases, the idle periods become increasingly rare.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-if-workloads-vary-with-the-queueing-delay&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-if-workloads-vary-with-the-queueing-delay&quot; aria-label=&quot;what if workloads vary with the queueing delay permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What if workloads vary with the queueing delay?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Arrival rates and service times are not always independent of queueing delay. For example, a online store becomes overloaded and slow during the holiday shopping season. Rather than continuing to browse, some customers may get fed up and leave, reducing the arrival rate of requests for individual web pages.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-if-we-had-multiple-servers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-if-we-had-multiple-servers&quot; aria-label=&quot;what if we had multiple servers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What if we had multiple servers?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Banks have multiple tellers, grocery checkouts have multiple cashiers. Clearly, there are often efficiency gains from having separate queues.&lt;/li&gt;
&lt;li&gt;On the other hand, a single queue is always better than separate queues when focusing on average response time because of variations in how long each task takes to service. One queue could be idle while another queue has multiple tasks&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;if-a-processor-is-90-busy-serving-web-requests-and-we-add-another-processor-to-reduce-the-load-how-much-will-that-improve-average-response-time&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#if-a-processor-is-90-busy-serving-web-requests-and-we-add-another-processor-to-reduce-the-load-how-much-will-that-improve-average-response-time&quot; aria-label=&quot;if a processor is 90 busy serving web requests and we add another processor to reduce the load how much will that improve average response time permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;If a processor is 90% busy serving web requests and we add another processor to reduce the load, how much will that improve average response time?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Unfortunately, there is not enough info to say since each web request needs processing time and disk I/O and network bandwidth. &lt;/li&gt;
&lt;li&gt;If arrival times and service times are exponentially distributed and independent of the system response time, the overall response time is the sum of the response times of the components `response time = sum for all arrival and service times(S / (1 - U))&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-are-some-conclusions-we-can-draw-from-real-world-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-are-some-conclusions-we-can-draw-from-real-world-systems&quot; aria-label=&quot;what are some conclusions we can draw from real world systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What are some conclusions we can draw from real world systems?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Almost all real world systems exhibit some randomness in their arrival process or service times&lt;/li&gt;
&lt;li&gt;Response time increases with increased load&lt;/li&gt;
&lt;li&gt;System performance is predictable across a range of load factors if we can estimate the average service time per request.&lt;/li&gt;
&lt;li&gt;Burstiness increases average response time.&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Real Time Scheduling and Overload Management]]></title><description><![CDATA[Notes on the different types of real-time scheduling systems]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/real-time-scheduling</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/real-time-scheduling</guid><pubDate>Tue, 12 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;real-time-scheduling&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#real-time-scheduling&quot; aria-label=&quot;real time scheduling permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Real Time Scheduling&lt;/h1&gt;
&lt;h2 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h2&gt;
&lt;p&gt;The software that runs the brakes in your car or autopilot on an airplane must work when called for, you can’t hit the brakes to stop after you have crashed your car. The change in value of a specific task over time is shown in the below graph.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 659px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/db376fa055a43ce98859b128396cf1f8/fff7d/Motivation.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 81.66666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAQABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAECBf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhADEAAAAe9YNIP/xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAEFAl//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAY/Al//xAAaEAACAgMAAAAAAAAAAAAAAAAAEQEQITFR/9oACAEBAAE/IdyRT4PIz//aAAwDAQACAAMAAAAQoA//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/ED//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/ED//xAAaEAACAwEBAAAAAAAAAAAAAAABEQAxQRBh/9oACAEBAAE/EECPPZq73iJoXAVkok//2Q==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/db376fa055a43ce98859b128396cf1f8/8ac56/Motivation.webp 240w,
/static/db376fa055a43ce98859b128396cf1f8/d3be9/Motivation.webp 480w,
/static/db376fa055a43ce98859b128396cf1f8/d2334/Motivation.webp 659w&quot;
              sizes=&quot;(max-width: 659px) 100vw, 659px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/db376fa055a43ce98859b128396cf1f8/09b79/Motivation.jpg 240w,
/static/db376fa055a43ce98859b128396cf1f8/7cc5e/Motivation.jpg 480w,
/static/db376fa055a43ce98859b128396cf1f8/fff7d/Motivation.jpg 659w&quot;
            sizes=&quot;(max-width: 659px) 100vw, 659px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/db376fa055a43ce98859b128396cf1f8/fff7d/Motivation.jpg&quot;
            alt=&quot;Oblivious Scheduling Results&quot;
            title=&quot;Oblivious Scheduling Results&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;three-techniques-to-increase-likelihood-that-threads-run-before-their-deadline&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#three-techniques-to-increase-likelihood-that-threads-run-before-their-deadline&quot; aria-label=&quot;three techniques to increase likelihood that threads run before their deadline permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Three techniques to increase likelihood that threads run before their deadline&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Over provisioning:&lt;/strong&gt; Make sure real-time tasks only use a fraction of the system’s total processing power. This is like taking 2 units when you know you can handle 16 units.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Earliest Deadline First:&lt;/strong&gt; Choose the task that has the earliest deadline first. However, this won’t always work with the given tasks due to it requiring both I/O and computation. Thus, always break tasks down into shorter units and use the deadlines of the shorter units.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Priority Donation:&lt;/strong&gt; The problem of &lt;em&gt;priority inversion&lt;/em&gt; occurs when a higher priority thread must wait for a lower priority thread to complete its work. This can be solved via Priority Donation, where a higher priority thread that is waiting for a lower priority thread donates its priority to the lower priority thread, allowing it to run and finish using that resource.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;questions-to-ask&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions-to-ask&quot; aria-label=&quot;questions to ask permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions to ask&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;For priority donation, do you actually change priority values by subtracting from the priority of the higher priority thread and adding to the priority of the lower priority thread or do you just set the lower priority thread’s priority to the priority of the higher priority thread?&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Virtual Memory and Address Translation]]></title><description><![CDATA[Notes on address translation and the impact of virtual memory]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/real-time-scheduling</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/real-time-scheduling</guid><pubDate>Tue, 12 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;general-address-translation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#general-address-translation&quot; aria-label=&quot;general address translation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;General Address Translation&lt;/h1&gt;
&lt;h2 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h2&gt;
&lt;p&gt;We want to store addresses in a different place than the computer expects. We can then use address translation to move between our what the computer thinks is storing stuff and the actual stuff.&lt;/p&gt;
&lt;h2 id=&quot;useful-things-we-can-do-with-address-translation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#useful-things-we-can-do-with-address-translation&quot; aria-label=&quot;useful things we can do with address translation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Useful things we can do with Address Translation&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Process Isolation:&lt;/strong&gt; Protect the operating system kernel and other applications against buggy or malicious code. This is done by limiting memory references by applications so that some applications cannot access that memory. Also, address translation can be used by applications to construct sandboxes for third party extensions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interprocess Communication:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;segmentation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#segmentation&quot; aria-label=&quot;segmentation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Segmentation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Translation happens on every instruction fetch, load, or store.&lt;/li&gt;
&lt;li&gt;Each virtual address space has holes, leading to efficient segmentation for sparse address spaces&lt;/li&gt;
&lt;li&gt;When is it OK to address outside valid range? This is how the stack grows&lt;/li&gt;
&lt;li&gt;What if not all segments fit in memory? One solution is swapping, where we save the segment of the current process to disk then switch to the next process. A better way is to only keep parts of memory we need.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;problems-with-segmentation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#problems-with-segmentation&quot; aria-label=&quot;problems with segmentation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Problems with Segmentation&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Must fit variable sized chunks into physical memory, there could be multiple gaps but no segment is small enough to fit in any of the gaps.&lt;/li&gt;
&lt;li&gt;Segmentation may move processes multiple times to fit everything.&lt;/li&gt;
&lt;li&gt;Limited options for swapping to disk&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;solutions-to-fragmentation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#solutions-to-fragmentation&quot; aria-label=&quot;solutions to fragmentation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Solutions to Fragmentation&lt;/h2&gt;
&lt;p&gt;Paging - Allocate physical memory in fixed size chunks where every chunk of physical memory is equivalent. The pages should be smaller than segments&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt; Use a page table per process, which resides in physical memory and contains a physical page and permission for each virtual page(valid bits, read, write, etc.)
The offset from virtual address is copied to physical address, the virtual page number is all the remaining bits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt; Page sharing is used in the kernel region of every process which has the same page table entries. Also used when different processes run the same binaries, user level system libraries, and shared memory segments between different processes. (Can actually share objects between processes as long as the page is mapped into the same place in the address space)&lt;/p&gt;
&lt;h2 id=&quot;page-table&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#page-table&quot; aria-label=&quot;page table permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Page Table&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Page Table Context Switch:&lt;/strong&gt; What need to be switched on a context switch? Page table pointer and limit.&lt;br&gt;
Pros: Simple memory allocation, easy to share
Cons: Poor when address space is sparse, table is really big&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Implementation:&lt;/strong&gt; Page tables are maps from Virtual Addresses to Physical Addresses. A simple implementation is a very large lookup table, but can also be implemented via Trees or Hash tables&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is in a Page Table Entry(PTE):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pointer to the next level page table or actual page&lt;/li&gt;
&lt;li&gt;Permission bits: valid bits, read-only, write-only, read-write&lt;/li&gt;
&lt;li&gt;Invalid PTE can imply region of address space is actually invalid or page/directory is just somewhere else other than memory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Using the Page Table Entry(PTE):&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Used in demand paging: keeps only active pages in memory, place others on disk and mark PTEs as invalid&lt;/li&gt;
&lt;li&gt;Used in Copy on Write: Unix fork gives copy of parent address to child. Address spaces disconnected after child created. Implementation - make copy of parent’s page tables, mark entries in both sets of page tables as read-only, page fault on write creates two copies&lt;/li&gt;
&lt;li&gt;Used in Zero Fill on Demand: New data pages stay zeroed, mark PTEs as invalid, page fault gets zeroed page.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;multi-level-translation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multi-level-translation&quot; aria-label=&quot;multi level translation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multi-Level Translation&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Only need to allocate&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;paging---caching-and-tlbs-demand-paging&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#paging---caching-and-tlbs-demand-paging&quot; aria-label=&quot;paging   caching and tlbs demand paging permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Paging - Caching and TLBs, Demand Paging&lt;/h1&gt;
&lt;p&gt;Problem: A single level page table can only have so many addresses, how do we get more space?&lt;/p&gt;
&lt;p&gt;Solution: Use a multilevel page table, where the first page table points to the second page table which points to the third page table&lt;/p&gt;
&lt;p&gt;Pros: Only need to allocate as many page table entries as we need for applications.(Sparse address spaces are easy)
Easy memory allocations, Easy Sharing at segment or page level(needs additional reference counting)&lt;/p&gt;
&lt;p&gt;Cons: one pointer per page, page tables need to be contiguous, two or more if more than 2 levels lookups per reference(very expensive!)&lt;/p&gt;
&lt;p&gt;Problem: Given a virtual address, how to map to physical address?
Solution: Use a hash table aka Inverted Page Table whose size is independent of the virtual address space. The size is directly related to the amount of physical memory.&lt;/p&gt;
&lt;p&gt;Cons: The complexity of looking things up in hardware in a hash table makes things hard. There will also be cache issues since each thing in the hash table is far from everything else. Total size of page table = number of pages used by program in physical memory&lt;/p&gt;
&lt;h2 id=&quot;address-translation-comparison&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#address-translation-comparison&quot; aria-label=&quot;address translation comparison permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Address Translation Comparison&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Technique&lt;/th&gt;
&lt;th&gt;Advantages&lt;/th&gt;
&lt;th&gt;Disadvantages&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Simple Segmentation&lt;/td&gt;
&lt;td&gt;Fast context switching since the segment map is maintained by the CPU&lt;/td&gt;
&lt;td&gt;External Fragmentation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Paging(Single-Level)&lt;/td&gt;
&lt;td&gt;No external fragmentation, fast + easy allocation&lt;/td&gt;
&lt;td&gt;Large table size, internal fragmentation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Paged Segmentation&lt;/td&gt;
&lt;td&gt;Table size ~ # of pages in virtual memory, fast + easy allocation&lt;/td&gt;
&lt;td&gt;Multiple memory references per page access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-Level Paging&lt;/td&gt;
&lt;td&gt;Table size ~ # of pages in virtual memory, fast + easy allocation&lt;/td&gt;
&lt;td&gt;Multiple memory references per page access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inverted Page Table&lt;/td&gt;
&lt;td&gt;Table size ~ # of pages in physical memory&lt;/td&gt;
&lt;td&gt;Complex Hash function required, no page table cache locality&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;how-is-translation-accomplished---the-memory-management-unit-mmu&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-is-translation-accomplished---the-memory-management-unit-mmu&quot; aria-label=&quot;how is translation accomplished   the memory management unit mmu permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How is Translation Accomplished? - The Memory Management Unit (MMU)&lt;/h2&gt;
&lt;p&gt;The MMU must translate virtual addresses to physical addresses for every instruction fetch, every load, and every store.&lt;/p&gt;
&lt;p&gt;Implementation:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the first level of the page table, Read PTE from memory, check that its valid, merge address&lt;/li&gt;
&lt;li&gt;In the second level page table, read and check the first level, then read and check and update the PTE&lt;/li&gt;
&lt;li&gt;Repeat for the n levels in the page table&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Problems: This is really slow, since a single load/store will require n reads, n being the number of levels in the page table.&lt;/p&gt;
&lt;p&gt;Solution: Caching - take advantage of the principle of locality to present the illusion of memory as the cheapest technology.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Temporal Locality:&lt;/strong&gt; Keep recently accessed data items closer to processor.
&lt;strong&gt;Spatial Locality:&lt;/strong&gt; Move contiguous blocks to the upper levels.&lt;/p&gt;
&lt;h3 id=&quot;how-to-make-address-translation-fast&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-to-make-address-translation-fast&quot; aria-label=&quot;how to make address translation fast permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How to make Address Translation Fast?&lt;/h3&gt;
&lt;p&gt;Cache the results of recent translation(the results of the MMU). Cache the PTE extra info, physical frame number, using the virtual page number as the key&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Translation Look Aside Buffer (TLAB):&lt;/strong&gt;
The name of the cache we use for translations. The TLAB records recent Virtual Page Number to Physical Frame number translation.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If the Virtual Page Number is present, return the Physical Address.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If not, the use the MMU to find and save the result of the physical address.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Instruction accesses spend a lot of time on the same page since their accesses are sequential&lt;/li&gt;
&lt;li&gt;Stack accesses have definite locality of reference,&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;We can have a multilevel TLAB with different size/speeds&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;sources-of-cache-misses&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sources-of-cache-misses&quot; aria-label=&quot;sources of cache misses permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sources of Cache Misses&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Compulsory:&lt;/strong&gt; Cold start or context switch - the first access to a block. Not much we can do here.
&lt;strong&gt;Capacity:&lt;/strong&gt; Cache cannot contain all blocks accessed by the program. Solution - increase cache size.
&lt;strong&gt;Conflict/Collision:&lt;/strong&gt; Multiple memory locations mapped to the same cache location. Solution - increase cache size or increase associativity.
&lt;strong&gt;Coherence(Invalidation):&lt;/strong&gt; Other processes eg I/O updates main memory, while the copy of main memory in the cache is not updated since it was some other process that modified main memory. THIS IS VERY COMMON IN MULTI-PROCESS PROGRAMS!
&lt;strong&gt;False Sharing:&lt;/strong&gt; Common cause of coherence misses.&lt;/p&gt;
&lt;h2 id=&quot;how-is-a-block-found-in-a-cache&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-is-a-block-found-in-a-cache&quot; aria-label=&quot;how is a block found in a cache permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How is a Block found in a cache?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Block:&lt;/strong&gt; Minimum quantum of caching. Data Select field is used to select data within blocks. Many caching applications don’t have data select fields.
&lt;strong&gt;Index:&lt;/strong&gt; Used to Lookup Candidate in a Cache.
&lt;strong&gt;Tag:&lt;/strong&gt; Used to identify actual copy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Direct Mapped Cache:&lt;/strong&gt;
Cons: Conflict Misses. Since data is stored 1:1 it is likely there is already something in that slot and we will need to evict that old piece of data&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;N-way set associative:&lt;/strong&gt; N entries per cache index.
&lt;strong&gt;Fully associative cache:&lt;/strong&gt; Every block can hold any line, address does not include a cache index. Compare cache tags of all cache entries in parallel.&lt;/p&gt;
&lt;h3 id=&quot;replacing-blocks-on-a-cache-miss&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#replacing-blocks-on-a-cache-miss&quot; aria-label=&quot;replacing blocks on a cache miss permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Replacing blocks on a cache miss&lt;/h3&gt;
&lt;p&gt;For Direct Mapping, there is only one possibility.
For Set associative or Fully associative, do it randomly or evict the least recently used block&lt;/p&gt;
&lt;h3 id=&quot;what-happens-on-a-cache-write&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-happens-on-a-cache-write&quot; aria-label=&quot;what happens on a cache write permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What happens on a cache write?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Write through:&lt;/strong&gt; The information is written to both the block in the cache and to the block in the lower level memory.
Pros: read misses cannot result in writes
Cons: The processor is held up on writes unless writes are buffered.
&lt;strong&gt;Write back:&lt;/strong&gt; The info is written only to the block in the cache. The modified cache block is written to main memory only when it is replaced.
Pros: repeat writes not sent to DRAM processor not held up on writes
Cons: More complex, read miss may require writeback of dirty data&lt;/p&gt;
&lt;h2 id=&quot;physically-indexed-vs-virtually-indexed-caches&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#physically-indexed-vs-virtually-indexed-caches&quot; aria-label=&quot;physically indexed vs virtually indexed caches permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Physically Indexed vs Virtually Indexed Caches&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Physically Indexed Caches (More common)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Address handed to cache after translation, the page table holds physical addresses&lt;/li&gt;
&lt;li&gt;Pros: Every piece of data has a single place in the cache and the cache stays unchanged, thus a cache remains unchanged through a context switch&lt;/li&gt;
&lt;li&gt;Cons: The TLB is in the critical path of the lookup&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Virtually Indexed Caches(Less common)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The address is handed to the cache before translation, the page table holds virtual addresses&lt;/li&gt;
&lt;li&gt;Pros: The TLB is not in the critical path of lookup&lt;/li&gt;
&lt;li&gt;Cons: The same data could be mapped in multiple places of cache and may need to flush cache on context switch.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-tlb-organization-makes-sense&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-tlb-organization-makes-sense&quot; aria-label=&quot;what tlb organization makes sense permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What TLB Organization Makes Sense?&lt;/h2&gt;
&lt;p&gt;Requirements: The TLB needs to be really fast since it is in the critical path of memory access. Also, there needs to be very few conflicts, otherwise miss times will be extremely high because we need to traverse the page table.&lt;/p&gt;
&lt;p&gt;TLB lookup is serial with cache lookup, thus. the speed of the TLB can impact the speed of access to the cache&lt;/p&gt;
&lt;!-- # Discussion Notes - TLB
## Paging and Address Translation - Conceptual Questions
If the physical memory size (in bytes) is doubled, how does the number of bits in each entry of the page table change?
It doesn&apos;t?
Answer: It increases by one bit since now there are twice as many physical pages so the physical page number needs to expand by 1 bit.

If the physical memory size (in bytes) is doubled, how does the number of entries in the page table change?
Doubled
Answer: No change, the number of entries in the page table is determined by the size of the virtual address and the size of a page, it isn&apos;t affected by the size of physical memory.

If the virtual memory size (in bytes) is doubled, how does the number of bits in each entry of the page table change?
It doesn&apos;t
Answer: No change, the size of each entry of the page table has nothing to do with the virtual memory
If the virtual memory size (in bytes) is doubled, how does the number of entries in the page map change?
It is multiplied by a factor of n, n being the number of levels?

If the page size (in bytes) is doubled, how does the number of bits in each entry of the page table change?
Doubled

If the page size (in bytes) is doubled, how does the number of entries in the page table change?
It is multiplied by a factor of n, n being the number of levels?

## Page Allocation
Suppose that you have a system with 8-bit virtual memory addresses, 8 pages of virtual memory, and 4 pages of physical memory.

How large is each page? Assume memory is byte addressed.
8 + 8 + 4

What will the page table look like if the program runs the following function? Page out the least recently used page of memory if a page needs to be allocated when physical memory is full. Assume that the stack will never exceed one page of memory?

What happens when the system runs out of physical memory? What if the program tries to access
an address that isn’t in physical memory? Describe what happens in the user program, the operating system, and the hardware in these situations.

## Address Translation
Consider a machine with a physical memory of 8 GB, a page size of 8 KB, and a page table entry size of 4 bytes. How many levels of page tables would be required to map a 46-bit virtual address space if every page table fits into a single page?

List the fields of a Page Table Entry (PTE) in your scheme.

Without a cache or TLB, how many memory operations are required to read or write a single 32-bit word?

With a TLB, how many memory operations can this be reduced to? Best-case scenario? Worst-case scenario? --&gt;
&lt;h1 id=&quot;demand-paging&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#demand-paging&quot; aria-label=&quot;demand paging permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Demand Paging&lt;/h1&gt;
&lt;h1 id=&quot;questions-to-ask&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions-to-ask&quot; aria-label=&quot;questions to ask permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions to ask&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;What is &lt;code class=&quot;language-text&quot;&gt;0x12345678&lt;/code&gt; &lt;code class=&quot;language-text&quot;&gt;123456&lt;/code&gt; is what? &lt;code class=&quot;language-text&quot;&gt;78&lt;/code&gt; is the offset in the page table?&lt;/li&gt;
&lt;li&gt;Caching in industry? What is it used for?&lt;/li&gt;
&lt;li&gt;How do we know that the main memory is different from the cached memory when detecting coherence misses? &amp;#x3C;—Apparently very hard to do :( take CS152&lt;/li&gt;
&lt;li&gt;Why isn’t LRU implemented using a heap&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Multiprocessor Scheduling]]></title><description><![CDATA[Notes on the different types of scheduling systems for multiprocessors]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/multiprocessor-scheduling</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/multiprocessor-scheduling</guid><pubDate>Mon, 11 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;bankers-algorithm&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bankers-algorithm&quot; aria-label=&quot;bankers algorithm permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bankers Algorithm&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Motivation: Avoid deadlocks when working with threads&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Idea: When a thread requests a resource, the OS checks if it would deadlock&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If so, wait for other threads to release resources&lt;/li&gt;
&lt;li&gt;If not, grant the resource right away&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Implementation: State max resources that thread needs. Allow thread to proceed if &lt;code class=&quot;language-text&quot;&gt;available resources - requested resources &gt;= max remaining needed by any thread&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Keeps system in a safe state&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;precise-exceptions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#precise-exceptions&quot; aria-label=&quot;precise exceptions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Precise Exceptions&lt;/h2&gt;
&lt;p&gt;At the time that an exception handler begins execution, there is a well-defined instruction
address in the instruction stream for which all prior instructions have committed their results and no following instructions (including the excepting one) have modified processor state.&lt;/p&gt;
&lt;h2 id=&quot;meltdown-security-flaw&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#meltdown-security-flaw&quot; aria-label=&quot;meltdown security flaw permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Meltdown Security Flaw&lt;/h2&gt;
&lt;p&gt;Many processors allowed timing windows in which illegal accesses could be performed
speculatively and made to impact cache state – even though the speculatively loaded data
was later squashed in the pipeline and could not be directly used.&lt;/p&gt;
&lt;h2 id=&quot;earliest-deadline-firstedf-scheduler&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#earliest-deadline-firstedf-scheduler&quot; aria-label=&quot;earliest deadline firstedf scheduler permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Earliest Deadline First(EDF) scheduler&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The scheduler to use for realtime systems. Runs the task with the earliest deadline first.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;beladys-anomaly&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#beladys-anomaly&quot; aria-label=&quot;beladys anomaly permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Beladys anomaly&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Increasing number of page frames increases number of page faults for FIFO, Random Page Replacement&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Multiprocessor Scheduling]]></title><description><![CDATA[Notes on the different types of scheduling systems for multiprocessors]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/multiprocessor-scheduling</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/multiprocessor-scheduling</guid><pubDate>Mon, 11 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h1&gt;
&lt;p&gt;Most computers are multiprocessors. How do we use multiple cores to run sequential tasks?
How do we adapt scheduling algorithms for parallel applications?&lt;/p&gt;
&lt;h1 id=&quot;sequential-scheduling---naive-approach&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sequential-scheduling---naive-approach&quot; aria-label=&quot;sequential scheduling   naive approach permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sequential Scheduling - Naive Approach&lt;/h1&gt;
&lt;p&gt;Create a single multi-level feedback queue(MFQ) with a lock so that only one processor can read/write from it at once. Each idle processor takes the next task off the MLFQ and runs it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Potential Problems&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Contention for MFQ lock:&lt;/strong&gt; Many Processes are fighting over the MFQ lock&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache Coherence Overhead:&lt;/strong&gt; Processes need to fetch the current state of the MFQ from the cache of previous processors to hold the lock. The cache for the current processor is likely not going to be of much use since most of it will need to be updated. Also, you are fetching/updating the cache data while you are holding the MFQ lock, causes further delays.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limited Cache Reuse&lt;/strong&gt; Since threads run on the first available processor, that processor probably doesn’t have the necessary data in its cache. &lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;commercial-operating-system-scheduler&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#commercial-operating-system-scheduler&quot; aria-label=&quot;commercial operating system scheduler permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Commercial Operating System Scheduler&lt;/h1&gt;
&lt;p&gt;Use a separate copy of the MFQ for each processor to maximize cache reuse.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Affinity Scheduling:&lt;/strong&gt; Once a thread has been scheduled on a processor, return it to the same processor when it is re-scheduled to maximize cache reuse. Each processor has its own copy of the queue to run threads from, only rebalance the queue length differences are large enough to compensate for the cache reload for the threads we move to different queues. Unfortunately locks are still necessary since per processor data structures must be protected by locks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Definition-Preempting a thread/process:&lt;/strong&gt; A thread is pre-empted when a higher priority thread is placed on the ready queue and the higher priority thread runs instead of the current thread.&lt;/p&gt;
&lt;h1 id=&quot;oblivious-scheduling&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#oblivious-scheduling&quot; aria-label=&quot;oblivious scheduling permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Oblivious Scheduling&lt;/h1&gt;
&lt;p&gt;Each thread is time sliced to available processors with no attempt to ensure threads from the same process run at the same time.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 625px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/3bcaeea825faaab6651f4dda45019abd/dfe3c/ObliviousScheduling.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 49.16666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAKABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAQAF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3pBmP//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAQUCX//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEABj8CX//EABgQAAIDAAAAAAAAAAAAAAAAAAEQADFB/9oACAEBAAE/IRcxhf/aAAwDAQACAAMAAAAQsw//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/ED//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/ED//xAAbEAACAgMBAAAAAAAAAAAAAAABEQAxECFRkf/aAAgBAQABPxBixfsW9304NQNnH//Z&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/3bcaeea825faaab6651f4dda45019abd/8ac56/ObliviousScheduling.webp 240w,
/static/3bcaeea825faaab6651f4dda45019abd/d3be9/ObliviousScheduling.webp 480w,
/static/3bcaeea825faaab6651f4dda45019abd/487e2/ObliviousScheduling.webp 625w&quot;
              sizes=&quot;(max-width: 625px) 100vw, 625px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/3bcaeea825faaab6651f4dda45019abd/09b79/ObliviousScheduling.jpg 240w,
/static/3bcaeea825faaab6651f4dda45019abd/7cc5e/ObliviousScheduling.jpg 480w,
/static/3bcaeea825faaab6651f4dda45019abd/dfe3c/ObliviousScheduling.jpg 625w&quot;
            sizes=&quot;(max-width: 625px) 100vw, 625px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/3bcaeea825faaab6651f4dda45019abd/dfe3c/ObliviousScheduling.jpg&quot;
            alt=&quot;Oblivious Scheduling Results&quot;
            title=&quot;Oblivious Scheduling Results&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Definition-Critical Path:&lt;/strong&gt; The minimum sequence of steps for the application to compute the result.&lt;br&gt;
&lt;strong&gt;Definition-Spin-then-wait:&lt;/strong&gt; If a lock is busy, the waiting thread spin-waits briefly for it to be released, and if it still busy, it blocks and looks for other work.&lt;br&gt;
Pros: Great if the lock is held for short periods of time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Potential Problems:&lt;/strong&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Critical Path Delay-&lt;/strong&gt; Preempting a thread on the critical path will slow down the end result.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bulk Synchronous Delay-&lt;/strong&gt; A common design pattern is to split work into equal sized chunks, do the work on the chunks, then communicate the work done to the next stage of computation(Think Google mapreduce). However, at each time step the work done is limited to the slowest processor, since all the chunks need to be finished before moving onto the next stage computation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Producer-consumer Delay-&lt;/strong&gt; Another common design pattern is the producer-consumer. The results of one thread are fed to the next thread, of which the results are fed to the next thread, etc. Preempting a thread in the middle of a producer-consumer chain will stall all of the processors in the chain.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Preemption of lock holder-&lt;/strong&gt; In spin-then-wait strategies for locks, the lock holder can be preempted-other tasks will spin-then-wait until the lock holder is rescheduled.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;I/O-&lt;/strong&gt; If a read/write happens in the kernel, the thread blocks. To use the processor when the thread is waiting, the application needs to have more threads and processors so the extra threads can run while one is waiting. However, if the thread does not block(ie a read when the file is in memory), then we cannot do time slicing since we have more threads than processes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;gang-scheduling&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#gang-scheduling&quot; aria-label=&quot;gang scheduling permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Gang Scheduling&lt;/h1&gt;
&lt;p&gt;Approach: Schedule all of the tasks of a program together. The application groups some work into a number of threads, and the threads run together or not at all. If the OS needs to schedule a different application or there aren’t enough idle resources, it preempts all of the processors of an application to make room&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 541px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/68225f1d5ad496c4f9a7567757729f07/8af7b/GangScheduling.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 55.00000000000001%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAECBf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhADEAAAAe8sDQ//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAEFAl//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAY/Al//xAAXEAADAQAAAAAAAAAAAAAAAAAAATEQ/9oACAEBAAE/IVRVimK5/9oADAMBAAIAAwAAABBjD//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8QP//EAB0QAQABAwUAAAAAAAAAAAAAAAERABCRITFBUWH/2gAIAQEAAT8QklZN9Jocjmj2c29HNv/Z&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/68225f1d5ad496c4f9a7567757729f07/8ac56/GangScheduling.webp 240w,
/static/68225f1d5ad496c4f9a7567757729f07/d3be9/GangScheduling.webp 480w,
/static/68225f1d5ad496c4f9a7567757729f07/fd5d3/GangScheduling.webp 541w&quot;
              sizes=&quot;(max-width: 541px) 100vw, 541px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/68225f1d5ad496c4f9a7567757729f07/09b79/GangScheduling.jpg 240w,
/static/68225f1d5ad496c4f9a7567757729f07/7cc5e/GangScheduling.jpg 480w,
/static/68225f1d5ad496c4f9a7567757729f07/8af7b/GangScheduling.jpg 541w&quot;
            sizes=&quot;(max-width: 541px) 100vw, 541px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/68225f1d5ad496c4f9a7567757729f07/8af7b/GangScheduling.jpg&quot;
            alt=&quot;Gang Scheduling Results&quot;
            title=&quot;Gang Scheduling Results&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Implementation in Commercial Operating Systems: The application pins each thread to a specific processor and mark it to run with high priority. The system uses the rest of the processors to run other applications without interfering with the primary application.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Problems&lt;/strong&gt;: As the number of processors increase, performance grows slower since some applications scale linearly with the number of processors, other achieve diminishing returns. &lt;/p&gt;
&lt;p&gt;Thus, it is usually more efficient to run two parallel programs with half the number of processors vs time slicing the two programs and gang scheduling.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Definition-Space Sharing:&lt;/strong&gt; Allocating different processors to different tasks. Efficient since it minimizes processor context switches. The problem occurs when the not all tasks start and stop at the same time, how do we know how many processors to use if the number changes over time?&lt;/p&gt;
&lt;h1 id=&quot;scheduler-activations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#scheduler-activations&quot; aria-label=&quot;scheduler activations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Scheduler Activations&lt;/h1&gt;
&lt;p&gt;Make the assignment and re-assignment of processors to applications visible to applications. Each application has an execution context(aka scheduler activation). Each application is explicitly informed when a processor is added to the allocation or taken away via an upcall. &lt;/p&gt;
&lt;p&gt;This leaves the question of how many processors should each process be assigned? This is an open research problem, there is a fundamental tradeoff between average response time and fair allocation of resources among different applications. In multiprocessors, average response time can be improved by giving extra resources to parallel interactive tasks as long as it does not cause long-running compute intensive parallel tasks to starve for resources.&lt;/p&gt;
&lt;h2 id=&quot;remaining-questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#remaining-questions&quot; aria-label=&quot;remaining questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Remaining Questions&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;What is the difference between MLFQ and MFQ? Are they the same thing just abbreviated differently?&lt;/li&gt;
&lt;li&gt;Even if one of the waiting processors picks up the pre-empted task, a single preemption can delay the entire computation by a factor of two, and possibly even more with cache effects. Why is this the case with Bulk synchronous delay for oblivious scheduling?&lt;/li&gt;
&lt;li&gt;Preempting a thread in the middle of a producer-consumer chain will stall all of the processors in the chain. Shouldn’t this be stall all of the processors after this thread in the chain?&lt;/li&gt;
&lt;li&gt;Performance as a function of the number of processors, for some typical parallel applications. Some applications scale linearly with the number of processors; others achieve diminishing returns. Why is this the case?&lt;/li&gt;
&lt;/ol&gt;</content:encoded></item><item><title><![CDATA[Data 100 Modeling]]></title><description><![CDATA[Notes on the different models]]></description><link>https://albertsu.netlify.app//posts/datascience/data-modeling</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/datascience/data-modeling</guid><pubDate>Sun, 10 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h2&gt;
&lt;p&gt;Predict unknown values based on known values&lt;/p&gt;
&lt;h2 id=&quot;modeling-process&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#modeling-process&quot; aria-label=&quot;modeling process permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Modeling Process&lt;/h2&gt;
&lt;p&gt;Choose a Model:** Constant model
Choose a Loss Function:** Squared Loss, Absolute Loss
Minimize average loss across entire dataset to determine optimal parameters&lt;/p&gt;
&lt;h2 id=&quot;correlation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#correlation&quot; aria-label=&quot;correlation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Correlation&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Correlation Coefficient (r):&lt;/strong&gt; Measures the strength of the LINEAR association between two variables&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;r is unitless and ranges between -1 and 1&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;if r = 1, x = y and all points fall exactly on the line&lt;/li&gt;
&lt;li&gt;if r = -1, -x = y and all points fall exactly on the line&lt;/li&gt;
&lt;li&gt;if r = 0, there is no linear association between x and y&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;r says nothing about causation or non-linear association. Remember correlation does not imply causation!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;r = average of the product of x and y, both measured in standard units
x&lt;em&gt;i in standard units = (x&lt;/em&gt;i - x) / o_x&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Covariance:&lt;/strong&gt; r * std&lt;em&gt;x * std&lt;/em&gt;y&lt;/p&gt;
&lt;h2 id=&quot;simple-linear-regression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#simple-linear-regression&quot; aria-label=&quot;simple linear regression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Simple Linear Regression&lt;/h2&gt;
&lt;p&gt;Motivation: Want to predict value of y for and given x. A naive attempt for getting children heights given parent heights is to compute the average value of y for each x value, then use those as predicts.&lt;/p&gt;
&lt;p&gt;Simple linear regression: y = a + bx
To determine optimal a and b, choose a loss function. If the loss function is squared loss, the objective function is mean squared error(MSE).&lt;/p&gt;
&lt;p&gt;To solve for the optimal parameters, we use the objective function and minimize the mean squared error by hand using calculus.&lt;/p&gt;
&lt;p&gt;b = r * (o&lt;em&gt;y/o&lt;/em&gt;x)
a = y&lt;em&gt;bar - b * x&lt;/em&gt;bar
This gives us parameter estimates for x and y.&lt;/p&gt;
&lt;h2 id=&quot;loss-surfaces&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#loss-surfaces&quot; aria-label=&quot;loss surfaces permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Loss Surfaces&lt;/h2&gt;
&lt;p&gt;Usually 3d, with axes being a, b and loss(y = a + bx)&lt;/p&gt;
&lt;h2 id=&quot;model-interpretation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#model-interpretation&quot; aria-label=&quot;model interpretation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Model Interpretation&lt;/h2&gt;
&lt;p&gt;Slope - measured in units of y per unit of x
New data needs to be similar to original data - you cannot predict the weight of a chihuahua’s weight given a model for golden retrievers
Visualize, then quantify - watch out for anscombe’s quartet
&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 449px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/6ac2ca895466097117e4582ba0a2174c/93dc1/Anscombes%20quartet.jpg&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 92.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAATABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAIBBf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhADEAAAAe8A0JCgf//EABYQAAMAAAAAAAAAAAAAAAAAAAEQIP/aAAgBAQABBQKwv//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8BH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EABQQAQAAAAAAAAAAAAAAAAAAADD/2gAIAQEABj8CH//EABgQAAIDAAAAAAAAAAAAAAAAAAEQIDFx/9oACAEBAAE/IYY7Ff/aAAwDAQACAAMAAAAQow88/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAwEBPxAf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPxAf/8QAGxAAAwADAQEAAAAAAAAAAAAAAAERITFhEIH/2gAIAQEAAT8QduR34JDTT4WvInIS7EWhY1zz/9k=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/6ac2ca895466097117e4582ba0a2174c/8ac56/Anscombes%20quartet.webp 240w,
/static/6ac2ca895466097117e4582ba0a2174c/57bab/Anscombes%20quartet.webp 449w&quot;
              sizes=&quot;(max-width: 449px) 100vw, 449px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/6ac2ca895466097117e4582ba0a2174c/09b79/Anscombes%20quartet.jpg 240w,
/static/6ac2ca895466097117e4582ba0a2174c/93dc1/Anscombes%20quartet.jpg 449w&quot;
            sizes=&quot;(max-width: 449px) 100vw, 449px&quot;
            type=&quot;image/jpeg&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/6ac2ca895466097117e4582ba0a2174c/93dc1/Anscombes%20quartet.jpg&quot;
            alt=&quot;AnscombesQuartetGraphs&quot;
            title=&quot;AnscombesQuartetGraphs&quot;
            loading=&quot;lazy&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;terminology&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#terminology&quot; aria-label=&quot;terminology permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Terminology&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Names for the x variable:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Feature&lt;/li&gt;
&lt;li&gt;Covariate&lt;/li&gt;
&lt;li&gt;Independent variable&lt;/li&gt;
&lt;li&gt;Explanatory variable&lt;/li&gt;
&lt;li&gt;Predictor&lt;/li&gt;
&lt;li&gt;Input&lt;/li&gt;
&lt;li&gt;Regressor&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Names for the y variable:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Output&lt;/li&gt;
&lt;li&gt;Outcome&lt;/li&gt;
&lt;li&gt;Response&lt;/li&gt;
&lt;li&gt;Dependent variable&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;adding-independent-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#adding-independent-variables&quot; aria-label=&quot;adding independent variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Adding independent variables&lt;/h2&gt;
&lt;p&gt;Use a weighted sum of coefficients and input variables.&lt;/p&gt;
&lt;h2 id=&quot;evaluating-models&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#evaluating-models&quot; aria-label=&quot;evaluating models permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Evaluating Models&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Look at Mean Squared Error(MSE) or Root Mean Squared Error(RMSE)&lt;/li&gt;
&lt;li&gt;Look at the correlations&lt;/li&gt;
&lt;li&gt;Look at a residual plot&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Root Mean Squared Error: Square root of the mean squared error. RMSE is in the same units as y. A lower RMSE indicates more accurate predictions. It is impossible to lower the RMSE just by adding features using the same data&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;R squared&lt;/strong&gt;: Used to measure the strength of the linear association between our actual y and predicted y. aka coefficient of determination.&lt;/p&gt;
&lt;p&gt;R^2 = variance of fitted values / variance of y&lt;/p&gt;
&lt;h2 id=&quot;ordinary-least-squares&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ordinary-least-squares&quot; aria-label=&quot;ordinary least squares permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Ordinary Least Squares&lt;/h2&gt;
&lt;h3 id=&quot;multiple-regression-using-matrix-multiplication&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multiple-regression-using-matrix-multiplication&quot; aria-label=&quot;multiple regression using matrix multiplication permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multiple regression using matrix multiplication&lt;/h3&gt;
&lt;p&gt;Multiple regression is of the form
&lt;code class=&quot;language-text&quot;&gt;y = theta_0 + theta_1 * x_1 + theta_2 * x_2 + ... + theta_p * x_p&lt;/code&gt;
We can restate this as a dot product
&lt;code class=&quot;language-text&quot;&gt;y = x^T * theta&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&quot;design-matrix&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#design-matrix&quot; aria-label=&quot;design matrix permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Design Matrix&lt;/h3&gt;
&lt;p&gt;Motivation: the mean squared error involves all observations at once, it would be nice to express our model in terms of all observations, not just one. We can put them into a design matrix.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Rows:&lt;/strong&gt; Correspond to observations. e.g. all features for data point 3
&lt;strong&gt;Columns:&lt;/strong&gt; Correspond to features. e.g. feature 1, for all data points&lt;/p&gt;
&lt;h2 id=&quot;residuals&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#residuals&quot; aria-label=&quot;residuals permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Residuals&lt;/h2&gt;
&lt;p&gt;Residuals are the difference between an actual and predicted value, in the regression context. We use the letter &lt;code class=&quot;language-text&quot;&gt;e&lt;/code&gt; to denote residuals, &lt;code class=&quot;language-text&quot;&gt;e_i = y_i - yhat_i&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The mean squared error is equal to the mean of the squares of its residuals.
We can stack all n residuals into a vector, called the residual vector.
&lt;code class=&quot;language-text&quot;&gt;residual vector = true y values - predicted y values&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Residuals are orthogonal to the span of X.
If our model has an intercept term(when our design matrix has a column of all 1s)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The sum and mean of the residuals is 0&lt;/li&gt;
&lt;li&gt;The average true y value is equal to the average predicted y value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Residual Plots:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;With simple linear regression with only 1 independent variables, we plot residuals vs x&lt;/li&gt;
&lt;li&gt;In the general case, use residuals on y axis vs fitted values on x&lt;/li&gt;
&lt;li&gt;A good residual plot has no pattern, if there is a curve, this is a sign that transformations or additional variables can help&lt;/li&gt;
&lt;li&gt;A residual plot should have a similar vertical spread throughout the entire plot. If it doesn’t there are probably issues with the accuracy of the predictions&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;unique-solutions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#unique-solutions&quot; aria-label=&quot;unique solutions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Unique Solutions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;There is always at least one model parameter that minimizes average loss.&lt;/li&gt;
&lt;li&gt;Constant models with a squared loss: a unique solution always exists&lt;/li&gt;
&lt;li&gt;Simple linear model with a squared loss: Any non constant value has unique mean, SD, correlation coefficient&lt;/li&gt;
&lt;li&gt;Constant model with absolute loss: Unique when there is an odd number y values, if there is an even number of y values, there are infinitely many solution.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;invertability-of-x-transpose--x&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#invertability-of-x-transpose--x&quot; aria-label=&quot;invertability of x transpose  x permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Invertability of X transpose * X&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Invertible iff it is full rank&lt;/li&gt;
&lt;li&gt;X transpose * X and X have the same rank&lt;/li&gt;
&lt;li&gt;Thus, X^T * X is invertible iff X has rank p + 1 (full column rank)&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;real-world-example---fairness-in-housing-appraisal&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#real-world-example---fairness-in-housing-appraisal&quot; aria-label=&quot;real world example   fairness in housing appraisal permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Real World Example - Fairness in Housing Appraisal&lt;/h1&gt;
&lt;h2 id=&quot;situation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#situation&quot; aria-label=&quot;situation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Situation&lt;/h2&gt;
&lt;p&gt;The cook county assessor’s office is in charge of assessing property values in order to determine property taxes. &lt;/p&gt;
&lt;h2 id=&quot;problem&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#problem&quot; aria-label=&quot;problem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Problem&lt;/h2&gt;
&lt;p&gt;The biased property value assessment resulted in a regressive tax, where rich people paid less and poor people paid more. In addition, rich people appealed more often than poor people, resulting in an even greater reduction of property tax. &lt;/p&gt;
&lt;h2 id=&quot;solution&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#solution&quot; aria-label=&quot;solution permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Solution&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Ask a Question:&lt;/strong&gt; What do we want to know? How to fairly value things for tax purposes. What are our metrics for success? Have both fairness and transparency in projections.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Acquisition and Cleaning:&lt;/strong&gt; What data do we have and what do we need? Housing Sales data between 2013-2019, Property Characteristics-ie age, bedrooms, baths, etc.How will we sample more data? Is our sample representative?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exploratory Data Analysis and Visualization:&lt;/strong&gt; What attributes are most predictive of sales price? Which are potentially problematic? Is the data predictive of sales price? &lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;takeaways&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#takeaways&quot; aria-label=&quot;takeaways permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Takeaways&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Accuracy is a necessary, but not sufficient condition of a fair system.&lt;/li&gt;
&lt;li&gt;Fairness and transparency are context-dependent&lt;/li&gt;
&lt;li&gt;Learn to work with contexts and consider how your data analysis will reshape them&lt;/li&gt;
&lt;li&gt;Keep in mind the power and limits of data analysis?&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;probability-and-generalization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#probability-and-generalization&quot; aria-label=&quot;probability and generalization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Probability and Generalization&lt;/h1&gt;
&lt;h2 id=&quot;random-variables&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#random-variables&quot; aria-label=&quot;random variables permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Random Variables&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Random Variable:&lt;/strong&gt; Represents a numerical value determined by a probabilistic event. &lt;/p&gt;
&lt;h3 id=&quot;probability-mass-function&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#probability-mass-function&quot; aria-label=&quot;probability mass function permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Probability Mass Function&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The distribution of a random variable X provides the probability that X takes on each of its possible values(discrete)&lt;/li&gt;
&lt;li&gt;The probabilities for all possible values of random variable X in a Probability Mass Function must sum to 1&lt;/li&gt;
&lt;li&gt;Each individual probability for a given value X must be between 0 and 1.
&lt;strong&gt;Joint Distributions:&lt;/strong&gt; Probability of two or more random variables taking on a specific set of values. Ie P(X=0, Y= 10) = (0.5) ** 10 for coin flips where X is heads and Y is tails
&lt;strong&gt;Marginal Distribution:&lt;/strong&gt; A way to go from the joint distribution to the distribution for a single variable. Ie consider all possible values of Y that can simultaneously happen with X and sum over all of the joint probabilities.&lt;br&gt;
∑y∈Y P(X=x,Y=y) = P(X=x)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Independent Random Variables:&lt;/strong&gt; Any two random variables are independent if and only if knowing the outcome of one variable does not alter the probability of observing any outcomes of the other variables.&lt;/p&gt;
&lt;h2 id=&quot;expectation-and-variance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#expectation-and-variance&quot; aria-label=&quot;expectation and variance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Expectation and Variance&lt;/h2&gt;
&lt;h3 id=&quot;expectation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#expectation&quot; aria-label=&quot;expectation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Expectation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The long run average of a random variable, also known as the expected value or expectation of a random variable.  &lt;/li&gt;
&lt;li&gt;E[X] = ∑ x∈X x ⋅ P(X=x)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Linearity of Expectation:&lt;/strong&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use when working with linear combinations of random variables. This holds true even when the random variables are dependent on each other.&lt;/li&gt;
&lt;li&gt;E[X+Y] = E[X] + E[Y]  &lt;/li&gt;
&lt;li&gt;E[cX] = c * E[X]  &lt;/li&gt;
&lt;li&gt;E[X−Y] = E[X] − E[Y]  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, E[XY]=E[X]E[Y] is only true when X and Y are independent random variables.&lt;/p&gt;
&lt;h3 id=&quot;variance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#variance&quot; aria-label=&quot;variance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Variance&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The variance of a random variable is a description of the variable’s spread, or how far values are apart from each other.  &lt;/li&gt;
&lt;li&gt;Var(X) = E[(X − E[X])**2]&lt;/li&gt;
&lt;li&gt;Var(X) = E[X**2] − (E[X])**2  &lt;/li&gt;
&lt;li&gt;Var(aX + b) = a**2 * Var(X) Is true if X is a random variable&lt;/li&gt;
&lt;li&gt;Var(X + Y) = Var(X) + Var(Y) Holds true if X and Y are independent  &lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;covariance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#covariance&quot; aria-label=&quot;covariance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Covariance&lt;/h3&gt;
&lt;p&gt;If the covariance is positive, the random variables are positively correlated(ie move in the same direction for stocks). If the covariance is negative, the random variables are negatively correlated. A covariance of 0 indicates the variables are independent.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Cov(X,Y) = E[(X − E[X]) * (Y − E[Y])]&lt;/li&gt;
&lt;li&gt;Cov(X,Y)= E[XY] − E[X]*E[Y]&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;risk&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#risk&quot; aria-label=&quot;risk permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Risk&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Risk:&lt;/strong&gt; Statistical risk is known as the expected loss, or the expected value of the model’s loss on randomly chosen points from the population.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;R(θ) = E[(X − θ)**2]&lt;/li&gt;
&lt;li&gt;To minimize risk, use R(θ) = E[(X − E[X]) ** 2] + (E[X] − θ) ** 2&lt;/li&gt;
&lt;li&gt;R(θ) = Bias + Variance = (E[X] − θ) ** 2 + E[(X − E[X]) ** 2]&lt;/li&gt;
&lt;li&gt;A low variance means the random variable will likely take a value close to θ, while a high variance means the random variable will take a value far from θ&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;empirical-risk-minimization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#empirical-risk-minimization&quot; aria-label=&quot;empirical risk minimization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Empirical Risk Minimization&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Since calculating the expected value of X requires complete knowledge of the population, since expected value is defined as probability X takes a specific value * that specific value. &lt;/li&gt;
&lt;li&gt;We can use a large random sample instead of the population when calculating the expected value of X&lt;/li&gt;
&lt;li&gt;Thus we can approximate E[X] ~ mean(x)&lt;/li&gt;
&lt;li&gt;Therefore, the empirical risk is the risk from using the large random sample instead of the population&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;multiple-linear-regression&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multiple-linear-regression&quot; aria-label=&quot;multiple linear regression permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multiple Linear Regression&lt;/h1&gt;
&lt;h2 id=&quot;questions-to-ask&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions-to-ask&quot; aria-label=&quot;questions to ask permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions to Ask&lt;/h2&gt;</content:encoded></item><item><title><![CDATA[Uniprocessor Scheduling]]></title><description><![CDATA[Notes on the different types of scheduling systems for uniprocessors]]></description><link>https://albertsu.netlify.app//posts/operatingsystems/uniprocessor-scheduling</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/operatingsystems/uniprocessor-scheduling</guid><pubDate>Sun, 10 Oct 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h2 id=&quot;motivation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#motivation&quot; aria-label=&quot;motivation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Motivation&lt;/h2&gt;
&lt;p&gt;Given multiple tasks, how do we decide which one to do first?&lt;/p&gt;
&lt;h2 id=&quot;uniprocessor&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#uniprocessor&quot; aria-label=&quot;uniprocessor permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Uniprocessor&lt;/h2&gt;
&lt;p&gt;Everything discussed below is work conserving - ie never leaves processor idle&lt;/p&gt;
&lt;h2 id=&quot;fifofcfs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fifofcfs&quot; aria-label=&quot;fifofcfs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fifo/FCFS&lt;/h2&gt;
&lt;p&gt;Perform each task in the order it arrives. Run each task until it finishes&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; No overhead, fair since every task waits their turn, simple&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; If a long task is scheduled before a short task, convoy effect dramatically raises average wait time. Average response time depends on task size distribution&lt;/p&gt;
&lt;h2 id=&quot;shortest-job-first-sjf--shortest-remaining-time-first-srtf&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#shortest-job-first-sjf--shortest-remaining-time-first-srtf&quot; aria-label=&quot;shortest job first sjf  shortest remaining time first srtf permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Shortest Job First (SJF) / Shortest Remaining Time First (SRTF)&lt;/h2&gt;
&lt;p&gt;Perform the shortest job first. Run each task till it finishes&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Optimal strategy&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Impossible, Increases the variance of average response time, Starvation can occur due to too many short jobs coming in which blocks off the longer jobs on the queue&lt;/p&gt;
&lt;p&gt;This shows that there is a tradeoff between reducing average response time and the variance of average response time&lt;/p&gt;
&lt;h2 id=&quot;round-robin&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#round-robin&quot; aria-label=&quot;round robin permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Round Robin&lt;/h2&gt;
&lt;p&gt;Tasks take turns on the processor, if the task is not completed in the given time quanta, it goes to the end of the queue&lt;br&gt;
&lt;strong&gt;Short time quanta:&lt;/strong&gt; Too much time spent context switching, no work will be done
&lt;strong&gt;Long time quanta:&lt;/strong&gt; Tasks spend a long time waiting for a turn
&lt;strong&gt;Infinite time quanta:&lt;/strong&gt; Same as FIFO
&lt;strong&gt;Zero time quanta:&lt;/strong&gt; SJF&lt;/p&gt;
&lt;p&gt;Simultaneous multithreading(SMT)/Hyperthreading: Switch between two processors on a cycle by cycle basis&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; No starvation&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Context switching takes time, need to evict cache in addition to registers of processor&lt;/p&gt;
&lt;h2 id=&quot;max-min-fairness&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#max-min-fairness&quot; aria-label=&quot;max min fairness permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Max min fairness&lt;/h2&gt;
&lt;p&gt;Iteratively maximize the minimum allocation given to a particular process until all resources are assigned&lt;/p&gt;
&lt;p&gt;If all processes are compute bound, this turns into round robin.&lt;/p&gt;
&lt;p&gt;If some processes don’t use entire share of processor becasue they are short running or IO bound, give those processes their entire request and redistribute the unused portion to remaining processes. Recursively distribute unused portions until nothing left. When no remaining requests can be fully satisfied, divide the remainder equally among all remaining processes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Good for IO bound tasks, no starvation&lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Computationally expensive&lt;/p&gt;
&lt;h2 id=&quot;multi-level-feedback&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multi-level-feedback&quot; aria-label=&quot;multi level feedback permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multi Level Feedback&lt;/h2&gt;
&lt;p&gt;Extension of Round Robin but uses multiple round robin queues, each with a different priority level and time quantum. Higher priority level queues go before lower priority queues, higher priority levels have shorter time quanta than lower levels.&lt;/p&gt;
&lt;p&gt;Meant to favor short tasks over long ones. New tasks enter at top, drops to lower queue when it uses up its time quanta. If task yields the processor bc it is waiting for IO, it stays on the same level, and is removed when task completes.&lt;/p&gt;
&lt;p&gt;Increases Priority when process receives less than its fair shares, reduces priority when process has more than fair share&lt;/p&gt;
&lt;p&gt;Goals: Run short tasks quickly, Low Overhead, no starvation, fair, defers maintenance tasks&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Bridges]]></title><description><![CDATA[Notes on bridges]]></description><link>https://albertsu.netlify.app//posts/crypto/bridges</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/bridges</guid><pubDate>Sun, 22 Aug 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;quick-primer-on-4-different-bridges&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#quick-primer-on-4-different-bridges&quot; aria-label=&quot;quick primer on 4 different bridges permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Quick Primer on 4 different bridges&lt;/h1&gt;
&lt;p&gt;Please note that some of this will be outdated. This also does not include layerzero, wormhole, synapse, abacus, NEAR’s rainbow bridge, and Ren, plus countless multisig bridges.&lt;/p&gt;
&lt;p&gt;This is a brief intro to Axelar, Celer, Gravity, and Nomad.&lt;/p&gt;
&lt;h2 id=&quot;axelar-network&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#axelar-network&quot; aria-label=&quot;axelar network permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Axelar Network&lt;/h2&gt;
&lt;h3 id=&quot;summary&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary&quot; aria-label=&quot;summary permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary:&lt;/h3&gt;
&lt;p&gt;Axelar network is built from the ground up using Cosmos SDK to interoperate between Cosmos chains, EVM chains, Bitcoin, and other PoS and PoW chains. Satellite is the cross-chain asset transfer app built on top of the network and has amassed over $37m TVL and 100k cross-chain transactions since launching in February. It has also recently become the official canonical bridge for Osmosis and plans to further expand its reach into the Cosmos and EVM ecosystem.&lt;/p&gt;
&lt;p&gt;Satellite currently supports Avalanche, Polygon, Terra, Osmosis, Moonbeam, Fantom, Ethereum and Cosmos Hub with plans to support all major EVM chains over the next couple months. &lt;/p&gt;
&lt;p&gt;Satellite connects all Cosmos chains via IBC and its GCP protocol with multiple ecosystems.
It’s built on top of Axelar’s “decentralized overlay network” that connects different blockchain stacks. Axelar serves as the translation layer that allows Cosmos assets to flow freely to all Axelar-interconnected networks and back. It is permissionless, meaning that anyone can join, submit transactions, relay, and validate.&lt;/p&gt;
&lt;p&gt;Axelar has been audited by Ackeeblockchain, Cure53, NCC, Oak Security, Commonprefix labs and independent researchers and is also dedicating at least 5% of AXL supply to an insurance fund/program that will help recuperate any stolen funds to ensure the safety of its users.&lt;/p&gt;
&lt;h3 id=&quot;security&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#security&quot; aria-label=&quot;security permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Security:&lt;/h3&gt;
&lt;p&gt;Axelar believes that bridging solutions should be at least as secure as the chains being bridged. Axelar’s solution is having a Cosmos chain, one with a similar validator set to other chains. Additionally, they are heavily invested in securing their smart contracts and in applying cutting-edge cryptography.&lt;/p&gt;
&lt;p&gt;The Axelar network isolates functionalities in modules at the Cosmos SDK level, e.g., one module for bitcoin, another for EVM chains, another for IBC transfers, etc. &lt;/p&gt;
&lt;p&gt;Each module handles the respective transactions from source and destination chains and are isolated from each other and messages can only be passed through a router module. If there is an issue with one or all chains, a special transfer command that can be supplied by the governance multisig can pause the router module.&lt;/p&gt;
&lt;p&gt;There is also minimal reliance on smart contracts and are only used for key-rotations and mint/burn operations.&lt;/p&gt;
&lt;p&gt;The mint/burn contracts can also be freezed in case of a compromise and have a rate-limit functionality that allows to minimize how much funds can be stolen in case of an attack. This is not enabled on the mainnet at the moment, but can be considered along with other “access control” policies to minimize attacks. &lt;/p&gt;
&lt;p&gt;There will also be an insurance fund/program of at least 5% of the AXL supply to compensate users in case of stolen funds. Axelar has also been audited by Ackeeblockchain, Cure53, NCC, Oak Security, Commonprefix labs and independent researchers and gone through a dozen audits. &lt;/p&gt;
&lt;h3 id=&quot;costs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#costs&quot; aria-label=&quot;costs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Costs:&lt;/h3&gt;
&lt;p&gt;Axelar currently has a set fee on each transfer that covers gas costs on source + destination chain. Axelar foundation subsidizes any increase in the destination gas cost if need be and is also considering subsiding fees further from its treasury. &lt;/p&gt;
&lt;p&gt;Transactions are also batched, reducing the gas costs for the users significantly. Axelar also has active implementation of threshold signatures that can be used to replace individual validator signatures and further save gas costs. While not currently deployed in EVM contracts, this is just one of the many code-level gas optimizations that Axelar will ship in the future.&lt;/p&gt;
&lt;p&gt;Users only pay the fee in the asset they transfer on the source chain, and all other fees (relaying / intermediary / destination chains) are covered by services around the network. &lt;/p&gt;
&lt;p&gt;App:
&lt;a href=&quot;https://satellite.axelar.network/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://satellite.axelar.network/&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;celer-network&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#celer-network&quot; aria-label=&quot;celer network permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Celer Network&lt;/h2&gt;
&lt;h3 id=&quot;summary-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary-1&quot; aria-label=&quot;summary 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary:&lt;/h3&gt;
&lt;p&gt;Celer Network is a multi-chain operating system built with Cosmos SDK. Celer released the world’s first EVM-supported inter-chain message SDK. and has a track record of no hacks for any product since Celer originated in 2018.&lt;/p&gt;
&lt;p&gt;Celer cBridge is a token bridge application built on top of Celer that supports 45 different tokens across 21 different blockchains and layer-2 rollups. cBridge has &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;400&lt;/mn&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;mi&gt;V&lt;/mi&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;h&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;400M TVL and has processed more than&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8888799999999999em;vertical-align:-0.19444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;MT&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.22222em;&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;an&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;ha&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;rocesse&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;ore&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;han&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;4B of cross-chain volume for 105K unique users with a daily volume of &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;50&lt;/mn&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;50M-&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.76666em;vertical-align:-0.08333em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;−&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;60M across 21 different blockchains.&lt;/p&gt;
&lt;p&gt;cBridge comes with two security models that every user can choose between, the Cosmos-consensus security model and an optimistic-rollup-style delay buffer security model. The consensus model is security that of a validator-based bridge, while the optimistic rollup style also has a delay buffer to allow an independent watchtower service to double check the message.&lt;/p&gt;
&lt;p&gt;Users have single-click UX with fast confirmation of the bridge between source and destination chains and with 2,500-3,500 daily active users comfortable with using Celer Network.&lt;/p&gt;
&lt;h3 id=&quot;security-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#security-1&quot; aria-label=&quot;security 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Security:&lt;/h3&gt;
&lt;p&gt;Cosmos-consensus Security Model:
Celer SGN is running as a Cosmos chain with the same level of liveness assumption which is very high like other Cosmos chains. Celer provides an L1-blockchain level security like Cosmos or Polygon as a Proof-of-Stake chain built on Tendermint with CELR as the staking asset. If a validator acts maliciously, their CELR will be slashed.&lt;/p&gt;
&lt;p&gt;Optimistic-rollup-style delay buffer Security Model:
Inter-chain dApps can maintain full security with an optimistic-style delay buffer. Instead of instantly processing a message through the consensus model, one can inject a mandatory delay buffer and run an independent watchtower service to double-validate the message on the source chain. If the watchtower service detects any inconsistency, it can prevent the message from being processed before the delay expires. &lt;/p&gt;
&lt;p&gt;For transactions larger than a certain amount, two-transactions are needed to make the bridge happen: a “commit” transaction that will trigger the time buffer and then after the time buffer, a “confirm” transaction. The watchtower system also monitors the bridge for small transactions as well to detect and prevent any unexpected smart contract bugs. There is also rate-limiting for token bridging as the last-resort to worst-case scenario. &lt;/p&gt;
&lt;p&gt;In addition, Celer cBridge smart contract has been heavily audited and also has a $2M ImmuneFi bug bounty. Celer Network also has a track record since 2018 of no hacking event happening for any product they have built. &lt;/p&gt;
&lt;p&gt;Costs:
cBridge charges the gas fee on the destination chain to cover the operation costs of validators. The fee is not related to the size of the transaction, unlike many other bridging solutions. &lt;/p&gt;
&lt;p&gt;Celer also has no plans to change the fee structure and remains committed to supporting inter-chain apps where IBC is not available. Unlike other bridges that plan on changing to percentage-based fees later, Celer will only charge a flat fee based on the size of the message passed to provide revenue for validators.&lt;/p&gt;
&lt;p&gt;There are also no platform fees charged by the Celer Network for token asset bridging.  &lt;/p&gt;
&lt;h3 id=&quot;app&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#app&quot; aria-label=&quot;app permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;App:&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://cbridge.celer.network/#/transfer&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://cbridge.celer.network/#/transfer&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;gravity-bridge&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#gravity-bridge&quot; aria-label=&quot;gravity bridge permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Gravity Bridge&lt;/h2&gt;
&lt;h3 id=&quot;summary-2&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary-2&quot; aria-label=&quot;summary 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary:&lt;/h3&gt;
&lt;p&gt;The Gravity Bridge blockchain is the trustless, neutral bridge between Ethereum and the Cosmos ecosystem. The principal focus of the Gravity community is on providing the most effective and secure bridge possible, instead of a DeFi application on the local chain. &lt;/p&gt;
&lt;p&gt;Gravity Bridge protocol focuses on creating a simple bridge design that focuses on providing better security by eliminating design complexity and using non-upgradeable contracts which have been audited by Certick, Least Authority and Cod4rena. &lt;/p&gt;
&lt;p&gt;The Gravity Bridge protocol provides strong censorship resistance guarantees and the bridge will remain live as long as the chain remains live, i.e. with more than 2/3 of validators active. &lt;/p&gt;
&lt;p&gt;Currently supports Ethereum and has plans to support additional EVM chains before the end of 2022. &lt;/p&gt;
&lt;p&gt;While there is not currently a set-aside for an insurance fund, one could easily be set aside from the community pool which contains 50% of $GRAV token distribution which could also contain a collection of assets. &lt;/p&gt;
&lt;h3 id=&quot;security-2&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#security-2&quot; aria-label=&quot;security 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Security:&lt;/h3&gt;
&lt;p&gt;Gravity Bridge is trustless, decentralized and highly efficient and offers the closest approximation of IBC security possible. It is highly decentralized with all funds directly controlled by validators with slashing to deter validators from acting in bad faith.&lt;/p&gt;
&lt;p&gt;The Gravity Bridge design means that the only way to attack the bridge is to go through the validators themselves. This results in a trustless bridge that costs less to operate than a custodial one. It is not possible for a validator to avoid signing a specific transaction or for a relayer to avoid relaying it. Anyone can submit evidence of a signature over a non-protocol message to slash a validator which makes it extremely difficult for validators to steal funds.&lt;/p&gt;
&lt;p&gt;The Gravity Bridge, like all bridges, has two components. A Solidity contract on Ethereum and a CosmosSDK module on the Gravity Bridge blockchain.&lt;/p&gt;
&lt;p&gt;The solidity contract that holds funds on Ethereum is merely 580 lines of code, which makes it compact and easy to review. It has been audited by three independent teams (Certik, Least Authority, and Code4rena), and it is not upgradable. It requires no trusted parties and can be temporarily paused by governance vote in case of a possible security breach. As a final layer of protection the Gravity Bridge blockchain performs a series of integrity checks that will halt the chain on any unexpected behavior.&lt;/p&gt;
&lt;p&gt;While there’s nothing set for an insurance fund at the moment, the $GRAV token holders can choose to use some funds from the large community pool to help recuperate stolen funds. &lt;/p&gt;
&lt;h3 id=&quot;costs-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#costs-1&quot; aria-label=&quot;costs 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Costs:&lt;/h3&gt;
&lt;p&gt;Robust relaying reward systems combined with reduced gas costs creates extremely fast &amp;#x26; reliable transfers with a decentralized, self-funded, relayer community&lt;/p&gt;
&lt;p&gt;Gravity Bridge batches withdraw transactions. This works like a rollup on Ethereum. Executing many transactions in a single shared context is far more efficient than doing so individually. This process provides huge efficiency gains, up to 96% reduction in gas cost.&lt;/p&gt;
&lt;p&gt;Once bridge traffic has matured, tx fees could be enabled by the community to sustain the community pool. These tx fees are payable in a wide variety of tokens, not solely in GRAV. Other mechanisms, like a portion of the inflation, could be used to fund the community pool. &lt;/p&gt;
&lt;h3 id=&quot;app-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#app-1&quot; aria-label=&quot;app 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;App:&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://spacestation.zone/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://spacestation.zone/&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;nomad&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#nomad&quot; aria-label=&quot;nomad permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Nomad&lt;/h2&gt;
&lt;h3 id=&quot;summary-3&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary-3&quot; aria-label=&quot;summary 3 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary:&lt;/h3&gt;
&lt;p&gt;Nomad is an interoperability protocol for generalized message passing. At its core, it uses an optimistic mechanism with fraud proofs to reduce the overhead of sending messages between chains and requiring 100+ validators. Nomad is designed to be non-custodial, trust-minimized and will be permissionless and decentralized in the future. With their unique watcher system, they forgo the need of 100+ validators and need only 1 good faith watcher to prevent fraudulent transactions.&lt;/p&gt;
&lt;p&gt;Unlike validator-based bridges, Nomad channels only require one “validator” and as a result, are easy to scale and deploy rapidly. It optimizes for high security, low cost, with the trade-off of mild latency to ensure fraud proofs can be confirmed on-chain. &lt;/p&gt;
&lt;p&gt;Nomad is already running in production on Ethereum and Moonbeam, and has &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;70&lt;/mn&gt;&lt;mi&gt;M&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi&gt;T&lt;/mi&gt;&lt;mi&gt;V&lt;/mi&gt;&lt;mi&gt;L&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;c&lt;/mi&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;v&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;70M+ TVL in contracts, and over&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.76666em;vertical-align:-0.08333em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;70&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.10903em;&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222222222222222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222222222222222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8888799999999999em;vertical-align:-0.19444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.13889em;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.22222em;&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;co&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.16666666666666666em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;an&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.03588em;&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.02778em;&quot;&gt;er&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;300M in total volume bridged. By the middle of Q2, Nomad will also support Arbitrum, Optimism, Polygon, BSC, Avalanche, and Fantom.&lt;/p&gt;
&lt;p&gt;Evmos will officially use Nomad and Connext as its bridging solutions, with Nomad as the settlement layer and Connext as the liquidity layer. Connext and Nomad have a deep partnership that enables the modular interoperability stack.&lt;/p&gt;
&lt;h3 id=&quot;security-3&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#security-3&quot; aria-label=&quot;security 3 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Security:&lt;/h3&gt;
&lt;p&gt;Nomad is composed of multiple agents — an updater, relayers, processors, and watchers. The most important is the updater, whose job it is to “validate” or update new roots. &lt;/p&gt;
&lt;p&gt;The updater is the sole “validator” in the system, and Nomad prevents liveness issues by downtime slashing + rotation, similar to that of a validator system. Relayers are like IBC relayers, and processors simply prove inclusion of messages on replicas — these are both permissionless roles. The watchers observe updaters to ensure that they are behaving correctly, and flag fraud if observed. Watchers allow Nomad to have a trust model where there only needs to be one honest actor, rather than a majority.&lt;/p&gt;
&lt;p&gt;Currently, the bridge is running in a permissioned environment with the core team running all updaters and watchers, but agents will become decentralized as Nomad continues to expand into the market.&lt;/p&gt;
&lt;p&gt;Nomad has partnered closely with Connext to provide a “fast liquidity” option. Connext uses liquidity pools to allow instant bridging whenever enough liquidity is available. If Connext’s liquidity network can’t offer sufficient liquidity, Nomad will default to its locking-and-minting layer, with the 30 minute dispute window. &lt;/p&gt;
&lt;p&gt;Nomad has been audited back in October 2021 and is currently in the middle of a Quantstamp audit — with no flagged issues thus far.&lt;/p&gt;
&lt;h3 id=&quot;costs-2&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#costs-2&quot; aria-label=&quot;costs 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Costs:&lt;/h3&gt;
&lt;p&gt;Nomad doesn’t have to pay 100+ validators to maintain the bridge and therefore requires minimal fees. Users will only need to incur network fees of the underlying chains.&lt;/p&gt;
&lt;p&gt;The off-chain agents are currently run by the Nomad core team who are subsidizing fees. As Nomad progressively decentralizes agent operations, new actors will probably begin to charge fees in exchange for relaying transactions across chains.&lt;/p&gt;
&lt;p&gt;The only cost Nomad charges is the underlying gas fees to submit transactions on various networks plus any premium agents add on top. For fast chains with lower gas fees, the cost should be in the order of cents to a couple dollars.&lt;/p&gt;
&lt;p&gt;There are no platform “toll” fees on Nomad, and they’re making an effort to reduce gas and network fees by implementing optimizations around enqueuing messages and processing.&lt;/p&gt;
&lt;p&gt;Users can use Metamask to send their transaction, and after a pre-defined latency for the chain pair (~30 mins for Ethereum), will receive their tokens on the destination chain. Nomad subsidizes the relaying and processing costs, and only requires users to pay network fees with no additional cost.&lt;/p&gt;
&lt;h3 id=&quot;app-2&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#app-2&quot; aria-label=&quot;app 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;App:&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://app.nomad.xyz/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;https://app.nomad.xyz/&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Osmosis]]></title><description><![CDATA[Intern Notes on Osmosis]]></description><link>https://albertsu.netlify.app//posts/crypto/osmosis</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/crypto/osmosis</guid><pubDate>Sun, 22 Aug 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;osmosis&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#osmosis&quot; aria-label=&quot;osmosis permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Osmosis&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Proof of stake with decentralized exchange app to provide liquidity, swap, and stake the tokens of blockchains from across the cosmos ecosystem&lt;/li&gt;
&lt;li&gt;Automated market maker connects to other tendermint based blockchains&lt;/li&gt;
&lt;li&gt;OSMO holders can delegate their assets to coinbase cloud public validator to earn a share of rewards (self staking and earn fees through token delegated to their validators)&lt;/li&gt;
&lt;li&gt;Innovating in liquidity pools by using osmosis’ governance processes and interoperable builder toolkit. OSMO native token in osmosis used for governance and paying transaction fees.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;superfluid-staking&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#superfluid-staking&quot; aria-label=&quot;superfluid staking permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Superfluid staking&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;If you deposit two supported tokens into pool can stake liquidity share to validators on the token’s chains&lt;/li&gt;
&lt;li&gt;Deposited asset will not only earn a share of fees from LP swap transactions but also earn rewards for helping to secure the chain&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Can provide liquidity to the osmosis AMM and participate in the native ecosystem of the tokens they hold by staking&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Example: OSMO&amp;#x3C;&gt; AKT pool’s LP tokens can secure both Osmosis and Akash networks&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;participating-in-osmosis&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#participating-in-osmosis&quot; aria-label=&quot;participating in osmosis permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Participating in Osmosis&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Validator nodes participate in osmosis consensus, propose blocks, and verify blocks proposed by other validators.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Over time validators will be able to incur more responsibility in the ecosystem, such as acting as price oracles or bridges&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Full Nodes: Interact with the osmosis blockchain&lt;/li&gt;
&lt;li&gt;Archival Nodes: Store history state of the chain&lt;/li&gt;
&lt;li&gt;Seed Nodes: Used to help nodes find and connect to peers&lt;/li&gt;
&lt;li&gt;Sentry Nodes: Used to stand between validators and rest of the network, protect validators from DDos&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Validator’s chance of being selected to perform work and earn rewards for doing so is determined by weight of OSMO staked to the validator&lt;/li&gt;
&lt;li&gt;OSMO holders may delegate their tokens to an active validator to  help secure the network and earn a portion of the rewards&lt;/li&gt;
&lt;li&gt;Validators set a commission fee between 5-100% of total rewards  earned by the delegators
14 day unbonding period for delegation, unbonded OSMO do not earn rewards but are eligible for losses due to slashing. Delegators also have full voting rights within Osmosis’ governance&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;rewards-and-economics-on-osmosis&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#rewards-and-economics-on-osmosis&quot; aria-label=&quot;rewards and economics on osmosis permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Rewards and economics on Osmosis&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Governance token to vote, pay transaction fees, and to provide rewards to participants for providing security&lt;/li&gt;
&lt;li&gt;Annual reward rate is 160% per annum for validators&lt;/li&gt;
&lt;li&gt;25% of released tokens will be issued to validators and their delegators as a reward for their work daily&lt;/li&gt;
&lt;li&gt;760,000 -&gt; 500,000 -&gt; 340,000 -&gt; 250,000 per day&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;three-types-of-fees-paid-out-to-users&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#three-types-of-fees-paid-out-to-users&quot; aria-label=&quot;three types of fees paid out to users permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Three types of fees paid out to users&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Transaction Fees: Any user who transact on the chain, distributed to OSMO stakers and validators&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Swap Fees: Any trader swapping assets on Osmosis&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Determined by LP parameters and size of trade&lt;/li&gt;
&lt;li&gt;Distributed to pool’s liquidity providers&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Exit Fees&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Percentage of LP shares and charged to liquidity providers who pull their liquidity out of a pool. Shares are burned and distribute their value to the other liquidity providers in the pool.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;45% of tokens released per epoch are designated as rewards for liquidity providers in pools&lt;/li&gt;
&lt;li&gt;Any designated rewards that are reduced from mining reward by governance will be directed to the Osmosis community pool instead.&lt;/li&gt;
&lt;li&gt;Inflation on Osmosis is structured around a thirdening model with token issuance cut by ⅓ each year&lt;/li&gt;
&lt;li&gt;100m initial supply 300 in first year 200 in second until a maximum supply of 1bn OSMO is issued&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;risk-of-participation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#risk-of-participation&quot; aria-label=&quot;risk of participation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Risk of participation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Slashing: Validators committing a slashable offense will result in loss of funds and reward for validators and any delegators who staked their OSMO to that validator&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;governance-on-osmosis&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#governance-on-osmosis&quot; aria-label=&quot;governance on osmosis permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Governance on Osmosis&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Will add new features that rely on active participation of the community&lt;/li&gt;
&lt;li&gt;Designed such that most efficient solution is reachable through the process of experimentation
5% of token released daily on osmosis are directed to the community pool.&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Lecture 1]]></title><description><![CDATA[First class for ISF 100J!]]></description><link>https://albertsu.netlify.app//posts/private/SocialComputing/Lecture-1</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/private/SocialComputing/Lecture-1</guid><pubDate>Mon, 18 Jan 2021 23:46:37 GMT</pubDate><content:encoded>&lt;h1 id=&quot;lecture-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lecture-1&quot; aria-label=&quot;lecture 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lecture 1&lt;/h1&gt;
&lt;h2 id=&quot;class-content&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#class-content&quot; aria-label=&quot;class content permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Class Content&lt;/h2&gt;
&lt;p&gt;Will learn&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Relationship between computing and gender, work, expertise, intelligence&lt;/li&gt;
&lt;li&gt;Ability to tell stories about computing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Won’t learn &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Are computers good or bad?&lt;/li&gt;
&lt;li&gt;What is the right policy for information distribution?&lt;/li&gt;
&lt;li&gt;What the future will look like?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;main-questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#main-questions&quot; aria-label=&quot;main questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Main Questions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;How did programming transform from a feminine to masculine occupation?  &lt;/li&gt;
&lt;li&gt;How did computers go from a symbol of repression to a symbol of liberation?  &lt;/li&gt;
&lt;li&gt;Why do so many Silicon Valley programmers go to burning man?  &lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;lecture-2&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lecture-2&quot; aria-label=&quot;lecture 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lecture 2&lt;/h1&gt;
&lt;h2 id=&quot;plan-of-the-course&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#plan-of-the-course&quot; aria-label=&quot;plan of the course permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Plan of the course&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Week 2-4 Computing before digital computers&lt;/li&gt;
&lt;li&gt;Week 5-10 How the cold war made computers the machines they are today&lt;/li&gt;
&lt;li&gt;Week 11-15 Contemporary internet platforms and algorithms&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;</content:encoded></item><item><title><![CDATA[Lecture 1]]></title><description><![CDATA[First class for CS189!]]></description><link>https://albertsu.netlify.app//posts/private/machinelearning/Lecture-1</link><guid isPermaLink="false">https://albertsu.netlify.app//posts/private/machinelearning/Lecture-1</guid><pubDate>Invalid Date</pubDate><content:encoded>&lt;h1 id=&quot;todo&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#todo&quot; aria-label=&quot;todo permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;TODO&lt;/h1&gt;
&lt;p&gt;Put readings on todo list can be found on class webpage
Put homeworks on todo list
Midterm 1 Monday march 16 in class
Discussion sections Monday-Wednesday&lt;/p&gt;
&lt;h1 id=&quot;core-material&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#core-material&quot; aria-label=&quot;core material permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Core material&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Find patterns in data and use them to make predictions&lt;/li&gt;
&lt;li&gt;Models + stats help us understand patterns&lt;/li&gt;
&lt;li&gt;Use optimization algorithms to learn the patterns&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;classification&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#classification&quot; aria-label=&quot;classification permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Classification&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Simplest Case: you have two choices, given data, make a prediction&lt;/li&gt;
&lt;li&gt;Knn best when few outliers&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;classifying-numbers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#classifying-numbers&quot; aria-label=&quot;classifying numbers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Classifying Numbers&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Turn points into grid of 0s and 1s based on the color of the grid&lt;/li&gt;
&lt;li&gt;Turn grid into a vector by flattening the vector&lt;/li&gt;
&lt;li&gt;Create hyperplane in the n-dimensional space to group things&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;testing-and-validation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#testing-and-validation&quot; aria-label=&quot;testing and validation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Testing and Validation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Train a classifier&lt;/strong&gt; - it learns to distinguish 7 from not 7&lt;/li&gt;
&lt;li&gt;Test the classifier on NEW images&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There are two types of error&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Training set error:&lt;/strong&gt; Fraction of training images not classified correctly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test set error:&lt;/strong&gt; Fraction of misclassified NEW images, not seen during training&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Outliers:&lt;/strong&gt; Points whose labels are atypical (e.g solvent borrowers who defaulted anyway)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Overfitting:&lt;/strong&gt; When the test error deteriorates because the classifier becomes too sensitive to outliers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hyperparameters:&lt;/strong&gt; Most ML algorithms have a few hyperparameters that control over/underfitting. eg k in k-nearest neighbors&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;select-classifiers-by-validation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#select-classifiers-by-validation&quot; aria-label=&quot;select classifiers by validation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Select classifiers by validation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Validation Set:&lt;/strong&gt; Hold back a subset of the labeled data &lt;/li&gt;
&lt;li&gt;Train the classifier multiple times with different hyperparameter settings&lt;/li&gt;
&lt;li&gt;Choose setting(hyperparameter + learning algorithm) that works best on validation set&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, we have 3 sets:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Training set:&lt;/strong&gt; Used to learn model weights&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validation set:&lt;/strong&gt; Used to tune hyperparameters, choose among different models&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test set:&lt;/strong&gt; Used as FINAL evaluation. Test set kept in vault, ran once, at the very end&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Kaggle.com&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Runs ML competitions, including our HWs&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We use 2 data sets: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;public set labels available during the competition&lt;/li&gt;
&lt;li&gt;private set labels known only to Kaggles&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;techniques-of-machine-learning-taught-in-class&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#techniques-of-machine-learning-taught-in-class&quot; aria-label=&quot;techniques of machine learning taught in class permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Techniques of Machine Learning Taught in Class&lt;/h1&gt;
&lt;h2 id=&quot;supervised-learning&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#supervised-learning&quot; aria-label=&quot;supervised learning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Supervised learning&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Classification: Is this email spam?&lt;/li&gt;
&lt;li&gt;Regression: How likely does this patient have cancer?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;unsupervised-learning&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#unsupervised-learning&quot; aria-label=&quot;unsupervised learning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Unsupervised learning&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Clustering: which DNA sequences are similar to each other?&lt;/li&gt;
&lt;li&gt;Dimensionality Reduction: What are common features of faces?&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;questions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#questions&quot; aria-label=&quot;questions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Questions&lt;/h1&gt;</content:encoded></item></channel></rss>