The website uses cookies. By using this site, you agree to our use of cookies as described in the Privacy Policy.
I Agree
Kev Peng
74 articles
My Web Markups - Kev Peng
  • In this reading, we’ve introduced the recursive definition of a binary tree as well as associated functions for creating, manipulating, and displaying binary trees. You should study these implementations because they are excellent examples of advanced applications of lists and pairs!
  • it is much more easier and readable, for example, to call binary-tree-right than caddr.
  • However, even though a tree is really a list behind the scenes, we want to avoid thinking about these implementation details when writing tree code. Therefore, we’ll define empty-tree and empty-tree? to be aliases for null and null? which hides the fact that we implement trees as lists.
  • We always have three elements, even though there are sometimes one or zero subtrees. This keeps the structure of the tree uniform so we can operate it in the say way irrespective of the number of subtrees at each node.
  • Putting all of this together, we can represent a tree as follows: The empty tree is null. The non-empty tree (a node) is a list of three values, (v l r): v, the value at the node, l, the left subtree, and r, the right subtree.
  • the “tail” of a tree will be a pair of subtrees instead of a single subtree!
  • Note that the only difference between a list and a tree is that a list can only have one sublist whereas a binary tree can have up to two subtrees.
  • Non-empty where it contains a datum and one or more children that are, themselves, trees.
  • root
  • leaves
  • interior nodes
  • node
  • we represent hierarchies using a data structure called a tree
  • the motivation behind the study of data structures which allow us to organize our data in various ways
  • take advantage of the structure of a data type, here a list, to make defining operations easier as well as more efficient
  • aliases or alternative names for car and last
  • ordering
  • In Scheme and Racket, you build lists with null (empty list) and cons (join a head and tail). You deconstruct lists with null? (check for empty list), car (grab the head), and cdr. Every other list operation we use can be built from those basics.
18 annotations
  • We also typically precompute a stopping point so that we don’t have to recompute it for each pass through the helper.
  • As the previous examples suggested, recursion over vectors is relatively straightforward, but usually requires that we have a helper procedure that includes additional parameters - the current position in the vector.
  • The vector-fill! procedure takes two arguments, the first of which must be a vector. It changes the state of that vector, replacing each of the elements it formerly contained with the second argument.
  • The mutator vector-set! takes three arguments – a vector vec, a natural number k (which must be less than the length of vec), and a Scheme value obj – and replaces the element of vec that is currently in the position indicated by k with obj. This changes the state of the vector irreversibly; there is no way to find out what used to be in that position after it has been replaced.
  • All of the previous procedures look a lot like list procedures, except that many are more efficient (e.g., vector? and vector-length take a constant number of steps; list? takes a number of steps proportional to the the length of the list and list-ref takes a number of steps proportional to the index).
  • The second argument is optional; if you omit it, the value that initially occupies each of the positions in the array is left unspecified. Various implementations of Scheme have different ways of filling them up, so you should omit the second argument of make-vector only when you intend to replace the contents of the vector right away.
  • vector
  • but with a preceding pound sign, #
  • The particular values that a vector contains at some particular moment constitute its state.
  • Unfortunately, list-ref works by cdr’ing down the list.
  • vectors are indexed and vectors are mutable.
11 annotations
  • n the specific case of tail-call optimization, we should only aggressively pursue tail-call optimization when we know that the inputs to our recursive functions will be large.
  • That is, we should not necessarily pursue the most optimized code upfront This is because optimizations frequently come with a cost: decreased code readability and more time and effort spent, sometimes with lesser gains that expected!
  • Premature optimization is the root of all evil.
  • Our implementation became decidedly more complicated. Rather than being a simple recursive function, append requires a helper function as well as a call to reverse. This complication also leads to potentially decreased performance in some situations. reverse must walk the entire input list to reverse it. So in effect, this tail-recursive version of append walks l1 twice: once to perform the reversal and once to cons its elements onto the front of l2. If the size of the inputs to append are small (thus not requiring us to use tail-recursion), then the tail-recursive version will be slower than its non-tail-recursive variant!
  • The left-hand expression arises in the tail-recursive variant of append. The right-hand expression arises with the naive version.
  • By cons-ing the elements in a top-down fashion rather than bottom-up fashion, we’ve reversed the order of l1 in the appended list!
  • Because they are local, you can also choose a pithier name for the helper so you less to type! Some folks use go, others use kernel:
  • letrec which acts like let* but also allows for recursive identifiers:
  • It is highly unlikely that replicate-helper would ever be used any other function other than replicate. So we would like to make replicatee-helper local to replicate reduce to avoid polluting the global namespace.
  • Updating the helper function to use the accumulator parameter. In the base case, this usually means returning the parameter as the overall result of the computation. In the recursive case, this usually means updating the parameter in some way when making the recursive call.
  • Creating a helper function that acts like the original function but includes an extra argument, an accumulator parameter, that captures the result of the function “so far” in the computation.
  • In the base case, we return the result argument since it is assumed to contain the result of traversing the list up until this point. Since we are in the base case of the recursion, we must have processed every element of the list, so the result argument contains our final result.
  • First, we’ll define a helper function that takes an extra argument that represents the result computed by replicate so far in its execution.
  • We call such functions that do all their work before they make their recursive calls tail-recursive functions. Tail-call optimization refers to both the process of making a function tail-recursive by the programmer as well as specific optimizations done by Racket behind the scenes to make tail-recursive functions efficient.
  • To do this, we’ll add an additional parameter to my-length that is the intended result of the computation so far.
  • What if we could reverse the steps? Rather than acting on the return value of the recursive call, can we figure out a way to add one to the result and pass that result to the recursive call? If we figured out some way of doing that, then we wouldn’t have any work to do after the recursive call and the resulting expression would not grow in size like it currently does.
  • However, Racket must still remember to perform all of these additions while it is carrying out the recursive my-length calls! This is where the inefficiency of the function lies: Racket needs to remember 1000000 (+ 1 ...) expressions, one for each my-length call made, so that they can be resolved after the last my-length call that returns 0 resolves.
  • memory inefficient.
18 annotations
  • Doc comments are meant for our collaborators and other potential users of this code to quickly learn about the program’s available functionality without having to dive through the details of the code. This audience also includes our future selves who may have forgotten these details!
  • A description of the computation that the function performs and the result value that it outputs. Any important details about the function’s behavior that a user of the function ought to know.
  • if a constraint only involves one parameter and it is short to express (either with a Racket expression, mathematical formula, or phrase), place it with the parameter list. If the constraint involves the interaction of multiple parameters or is complicated, place it in the description where there is more prose.
  • This section describes the types of each parameter again by way of predicates that usually test type identity. In addition to the predicates, we might also specify other essential properties of the parameters that aren’t necessarily captured in the predicate.
  • by a predicate,
  • the arrow (->)
  • The signature of a function describes what it takes as input and produces as output.
  • Note that throughout, we use triple semicolons (;;;) to encase our doc comments to make them stand out from other comments we might write.
  • Having to execute our function to figure out what it does is not ideal. What if the function we’re considering takes a long time to execute? What if the function is deeply nested inside of our system and, thus, difficult to execute on its own? What if the function’s behavior is so convoluted we don’t even know what we could pass to the function to experiment?
  • Is our translation of our solution to a program correct?
  • Is our solution (our algorithm) correct?
11 annotations
  • If the helper procedure you’re defining uses any of the parameters of the main procedure, it needs to come after the lambda. Otherwise, it is generally a better idea to do it before the lambda.
  • In the second case, it is done every time the procedure is executed.
  • Regardless of whether square is also defined outside this definition (e.g., as a procedure that draws squares), the local binding gives it the appropriate meaning within the lambda-expression that describes what hypotenuse-of-right-triangle does.
  • Yes, one can use a let- or let*-expression to create a local name for a procedure.
  • But that definition requires DrRacket to build the list every time we call the vowel? procedure.
  • One moral of this story is whenever possible, move your bindings outside the lambda.
  • What we’d like to do is to declare the values once, but keep them local to years-to-seconds. The strategy is to move the let outside the lambda.
  • About a decade ago, SamR said, “When you have sons between the ages of 5 and 12, you’ll understand.”
  • each binding specification in the binding list is completely processed before the next one is taken up
  • let*
  • You have to think of the local bindings coming into existence simultaneously rather than one at a time.
  • Within one binding list, all of the expressions are evaluated before any of the names are bound.
  • ; Combining the binding lists doesn't work!
  • this is the second argument to + and is outside the body of the let, so we do not substitute for it. Presumably, this x is bound by a different construct, e.g., a define.
  • In contrast, if you use let to define your local names, these names are completely inaccessible to other pieces of code.
  • When we do a new top-level define (Racket only allows that in the interactions pane), we permanently replace the old value associated with the name. That value is no longer accessible. In contrast, when we use let to override the value associated with a name, as soon as the let binding is finished, the previous association is restored.
  • global variables
  • local variables
  • Values named by define are available essentially everywhere in your program. In contrast, values named by let are available only within the let expression.
  • The programmer can compute the value of the subexpression just once, bind a name to it, and then use that name whenever the value is needed again.
  • a binder
  • There is. Raacket provides let expressions as a way to bind values to names. A let-expression contains a binding list and a body. The body can be any expression, or any sequence of expressions, to be evaluated with the help of the local name bindings. The binding list takes the form of a parentheses enclosing zero or more binding expressions of the form (name value).
  • Rewrite procedures that do a sequence of steps by using one procedure for each step
  • once when counting the vowels and once when counting the consonants.
  • we ask if many letters are a vowel twice
  • Second, we call (string->list str) twice.
  • First, we call (char-downcase ch) as many as five times.
  • parameter bindings are local – they apply only within the body of the procedure.
  • by means of a definition
29 annotations
  • a lower bacterial load and a relatively low abundance of the bacterial genus Faecalibacterium.
  • immune system,13,17 synthesis and metabolism of metabolites and neurotransmitters,18 and activation of the vagus nerve.
  • Interestingly, it is over 100 years ago since George Porter Philips put forward the concept of treating melancholia with lactobacillus;164 with more clinical research, we may be able to validate how much he was ahead of his time.
  • The reverse is likely also true. Looking toward the future, the microbiome might be the place to probe when developing new treatments for MDD
  • As discussed earlier in the review, microbiome features such as an altered microbial composition, or alpha diversity, are often associated with MDD symptoms. FMT has been shown to transfer these features to the recipient.160 While dedicated studies are not yet available, a recent study on the effect of FMT on inflammatory bowel disease has reported improved mood in recipients of a healthy microbiome
  • Microbiome interventions specifically designed to improve mental health are termed psychobiotics.
  • prebiotics and probiotics.
  • it has been speculated upon that the microbiome-targeted effects of psychotropic drugs might play a role in the mechanism of action or in the side effects of these medications.
  • A general trend among the microbiomes of depressed patients and animals with increased depressive-like behavior is a drop in alpha diversity, an increase in relative abundance of microbes associated with a proinflammatory state, and a heightened state of inflammation in the host
  • While only shown in rodents, the behavioral outputs of these studies and their respective translational implications support the notion that certain compositions of the microbiome can affect behavior and mood.
  • both mice and rats that received a fecal microbiome transplantation (FMT) from depressed humans displayed a heightened state of inflammation and increased anhedonia-like (as measured by the sucrose preference test) and anxiety-like behavior (as measured by the open field test and elevated plus maze test) compared to those who received FMT from healthy volunteers.
  • depressed individuals were more likely than their healthy counterparts to fall into a certain enterotype
  • a classification of living organisms based on their bacteriological ecosystems in the gut microbiome
  • diversity of MDD patients tends to be lower overall, with a higher abundance of bacterial phyla generally associated with inflammation, like Bacteroidetes, and a reduction in phyla associated with a decrease in inflammation, like Firmicutes
  • MDD patients have an altered gut microbiome composition when compared to healthy controls
  • some studies have also shown that transferring the microbiome of a depressed individual into a healthy rodent can induce depressive-like behavior in the recipient.
  • A wealth of studies, from different perspectives and experimental approaches, link the gut microbiome to MDD
  • an increase in the relative abundance of the genera Bifidobacterium and Lactobacillus and the species Blautia coccoides and Eubacterium rectale, as well as with an increase in microbiota diversity,
  • potential positive effects on brain and behavior
  • a dampening or abolishment of microbiota compositional oscillations
  • circadian disruptions can affect the intestinal microbiota
  • reduced levels of Lactobacillus, a health-promoting genus that is abundant in early life, and reduced SCFA production
  • high-stress microbiomes featuring an increased diversity of Clostridium genera, which is generally associated with inflammation and disease
  • Many studies exist in animal models showing the impact of stress on the microbiome—including rodents,29,36,37,46,75,76 pigs,77 and primates.
  • that stress influences the microbiome
  • also to shorten episodes of depression
  • associated with an increased abundance of bacteria with anti-inflammatory properties.
  • diet can be effective in alleviating MDD symptoms.
  • quality of diet is known to influence the severity of MDD
  • diet is known to markedly shape the composition of the gut microbiome.
  • In the context of MDD and the microbiome, two such factors stand out especially—namely, diet and stress.
  • we will examine evidence suggesting that the microbiome is altered in MDD, and discuss why the microbiome should be considered during MDD treatment
  • Neurodevelopmental differences—including neurogenesis, a process that is dysregulated in depression—have been observed in mice with a humanized microbiome, where specific microbes seemed to be necessary for normal neurodevelopment.
  • The gut microbiome is also known to modulate the physiology and behavior of the animal.
  • stress can change the microbiome in mice, specifically decreasing Lactobacillus
  • interpreting changes in mood and behavior in animals is challenging
  • Factors that influence the microbiome and, in turn, the onset/development of depression include lifestyle, medications, stress, and dietary habits
  • HPA axis becomes hyperactivated
  • In major depressive disorder, alterations in the gut microbiota negatively affect the gut–brain axis
  • depression has been associated with impairment of the microbiome’s ability to produce neuroactive metabolites and with disrupted intestinal barrier function
  • Alterations in the microbiome can also lead to hyperactivation of the immune system, with production of inflammatory cytokines typically observed in depression.
  • microbiota could influence central nervous system function directly by means of neuronal activation of stress circuits
  • gut microbiota plays a role in the programming and reactivity of the HPA axis
  • episodes of depression are associated with a dysregulated hypothalamic–pituitary–adrenal (HPA) axis,25 and conversely, improved depressive symptoms are associated with stabilization of the HPA axis.
  • the gut microbiome has been linked to several physiological functions relevant to depression
  • major depressive disorder (MDD).
  • Alzheimer’s disease
  • the microbiome–gut–brain axis (MGBA)
  • Fecal Microbiome Transplantation as a Therapy for MDD
  • the bacteria on the teeth of his patients were the source of their psychiatric conditions
  • Élie Metchnikoff, adhered to the idea that bacteria in fermented milk were beneficial against autointoxication
  • the syphilis-causing microbe Treponema pallidum was responsible for filling large parts of Victorian mental asylums
  • how the microbiota might become a therapeutic target for MDD
  • the interplay between the microbiota and MDD
  • factors that affect the onset/development of MDD that also greatly impinge on the composition of the gut microbiota—especially diet and stressful life events
  • the gut contains the largest number of neurons in the body, after the brain
  • three facets
  • the gut microbiome is in communication with the brain, through the gut–brain axis.
58 annotations
  • Feeling Depressed? Bacteria in Your Gut May Be to Blame
  • These behavior changes in mice affect such things as appetite, weight gain and activities like swimming.
  • several recent studies show.
  • research was published
  • Recent findings
  • a 2019 review in the Journal of Experimental Medicine
  • Human Microbiome Project.
  • These behavior changes in mice affect such things as appetite, weight gain and activities like swimming.
  • Until now, though, no one has been able to single out specific species of microbes linked to a mental illness. This month, an international research team for the first time identified dozens of species of gut microbes involved in depression by comparing patients diagnosed with the disorder to healthy people. These 47 species are a tiny fraction of the gut’s microbial diversity, which includes other single-celled organisms, thousands of virus species and fungi.
  • Bacteroides, here seen in a colored scanning electron micrograph, are the most common bacteria found in the human intestinal tract.
  • “When you give these mice the microbes from depression, they begin to behave in a depressive-like way,” said psychiatrist Julio Licinio at State University of New York Upstate Medical University in Syracuse. These behavior changes in mice affect such things as appetite, weight gain and activities like swimming.
  • chemically altering nerve signals going into the brain, which alter brain chemistry and therefore behavior, mood and, we believe, depression and anxiety.
  • Some common gut bacteria, for example, help generate neurotransmitters such as serotonin, which affects neural activity related to mood and memory. It’s commonly used to treat depression. Others make an amino acid called gamma-aminobutyric acid that naturally blocks some brain signals. It’s used in medication to relieve anxiety and improve mood.
  • While no one yet knows exactly why, patients with various psychiatric disorders including depression, bipolar disorder, schizophrenia and autism-spectrum disorder have significant disruptions in the composition of their gut microbiome.
  • indiscriminate use of antibiotics and other sanitation measures eliminated the harm that bacteria cause at the expense of the protection they can provide.
  • a potential mechanism for a mental illness that affects an estimated 350 million people world-wide
  • transmissible
  • infect mice and rats with mental disorders, including depression and anxiety, by transplanting stool samples, which contain gut microbes, from human patients into laboratory animals, several recent studies show.
  • often associated with gastrointestinal disorder
  • the microbial menagerie living in our digestive tract may help regulate brain function, including mental health
  • we can have behavioral effects that are going to have impact on overall well-being.”
  • directly by affecting nerve signals and indirectly through chemicals absorbed into the bloodstream
  • Conversely, other bacteria in the gut appear to produce some of the same substances used by doctors to treat depression and may naturally play a role in maintaining our emotional balance.
  • psychobiome
24 annotations