--- layout: archive title: Zulip Chat Archive permalink: /stream/116395-maths/topic/out_param.20again.html ---
There are things I understand better after one year of Lean. But out_param is not among those. At https://gist.github.com/PatrickMassot/3c40ee89b1f0329432060e257c7e7cf3 does anyone know how to make Lean happy on line 105, without using the commented line 106? This is a standalone file that works with current mathlib
Are you going after the inverse function theorem?
I'm on commit 05449a061744f8142bfc5396184e33ef19b08b82
from under a week ago and it doesn't compile for me -- do I need to update mathlib?
fixed with a sorry
. What does id - u
mean?
Probably... the topology of the topology/
directory changed a bit.
Patrick's error without the @
is
don't know how to synthesize placeholder ⊢ out_param (Type ?)
and his function with the out_param
s is
lipschitz_global_inverse : Π {α : out_param (Type u_3)} [_inst_1 : out_param (normed_field α)] {E : Type u_4} [B : banach_space α E], (E → E) → E → E
So you promised Lean that alpha would be inferred using unification, but it couldn't do it.
variables {α : out_param $ Type*} [out_param $ normed_field α]
So you have u : E -> E
, and you want Lean to spot banach_space α E
using type class inference and then realise that clearly you want α
in that missing first slot.
@Kevin Buzzard Yes I want Lean to find alpha
@Sebastien Gouezel Yes, I'm going after the inverse function theorem. I was hoping that @Jeremy Avigad would give the mean value inequality while I was preparing on the Lipschitz side. But it looks like I'll also have to do the mean value inequality
Can anyone help me in this thread?
@Mario Carneiro maybe?
The MVT doesn't look too bad. I will put it next on my list, though I can't promise to do it soon. (@Patrick Massot if you do it let me know.)
@Patrick Massot I was toying with the idea of implementing the inverse/implicit function theorem in the style of McDuff/Salamon. While I haven't done that, I did implement the necessary Newton Picard iteration in the version of Audin / Damian, see https://github.com/jdsalchow/mathlib/blob/newton_picard/src/analysis/normed_space/newton_picard.lean
Maybe some of it is useful in your efforts?
notation `∃!` binders `,` p:(scoped P, P) `,` `moreover` q:(scoped Q, Q) := exists_unique p ∧ ∀ x, p x → q x`
"moreover" :-)
@Jan-David Salchow Nice! I'm pretty sure that main proof can be mathlib'ed. I can't spend too much time on this right now, because have exams to prepare and I promised to work on uniform spaces. We definitely need some coordination about the basic definitions, like lipschitz_within_with
that I also defined in my file, and the space of differentiable functions that you defined. There are very basic questions not yet adressed in deriv.lean
, like: do we want to talk about the derivative of f
for any f
, getting junk if f
has no derivative, or do we want bundled differentiable maps like you did? How do we define C^k functions? C^infinity? @Jeremy Avigad should tell us what he thinks here
That being said, I'm still interested in the question that started this thread. Can anyone help me here?
There are things I understand better after one year of Lean. But out_param is not among those. At https://gist.github.com/PatrickMassot/3c40ee89b1f0329432060e257c7e7cf3 does anyone know how to make Lean happy on line 105, without using the commented line 106? This is a standalone file that works with current mathlib
@Mario Carneiro could you help me here?
To play well with the rest of the module hierarchy, you should take the out_param off alpha
actually just take all the out_params off
module doesn't work like that anymore
instance inhabited_vector_space {k : Type*} {α : Type*} [discrete_field k] [add_comm_group α] [vector_space k α] : inhabited α := ⟨0⟩
this is a bad idea
you don't even need all this stuff about k but it's going to make typeclass search get lost
this should just say that an add_comm_group
is inhabited... and it should be a local instance
Thanks!  Is it something about inv_fun_on
or something?
In your definition of fixed_point
you use nonempty
, but for the properties you use inhabited
. This seems reverse of what I would expect
https://gist.github.com/PatrickMassot/3c40ee89b1f0329432060e257c7e7cf3#file-out_param_hell-lean-L48
oh you found it
If you are okay with using nonempty
for fixed_point
(and going classical), then you should use nonempty
for the properties too
I must admit I used nonempty and inhabited interchangeably
So should I replace all by inhabited by nonempty?
I tried removing all out_param, but Lean still does not find my base field
Lean won't find the base field unless you include it in your functions, like a normal type
Why is that?
Is Lean missing something fundamental here?
concretely, that means alpha should be explicit in lipschitz_with_translate
and lipschitz_global_inverse
Lean can't infer alpha, it appears nowhere in the theorem
It appears in the instance for E
instances don't get pulled in unless the types are
Consider the point of application of your definition, lipschitz_global_inverse u
. Lean knows u : E -> E
, and knows the result has type E -> E
, but nothing else tells it what α
could be
lean knows that E
is a banach space over the local α
, but doesn't know if this should be the same α
that is used in the theorem
long story short, this is just standard explicitness rules. Usually types appear as dependencies in further arguments, so they are usually implicit. In this case alpha is never used, so it has to be explicit
This instance is pulled in, but it's not enough
But I understand this is hopeless
it gets pulled in the theorem but not in the use
This is the effect of the out_param
. Before, with out_param
, this could be inferred because you have an order like u
known -> E
known -> B : banach_space ? E
searched to determine α
-> α
known. Now you have u
known -> E
known -> no typeclass search because α
unknown -> fail
Or are you going to promise to me that a banach space will never have two scalar fields?
I will remind you that this is why we don't use out_param here anymore
I certainly want complex banach spaces to be also real banach spaces
One more question about this: Mario, do you mean https://github.com/leanprover-community/mathlib/blob/master/src/analysis/normed_space/basic.lean#L327 should not have out_param anymore?
{% endraw %}Last updated: Apr 24 2020 at 19:02 UTC


Hear Panic! At The Disco’s theatrical cover of ‘Frozen 2’ song ‘Into The Unknown’
Brendon Urie and co take on Elsa’s song
Panic! At The Disco have released their rendition of ‘Into The Unknown’, a song from the forthcoming sequel to the hit Disney movie Frozen.
Panic’s version of the song – sung in the movie by Elsa – features guitar riffs and rousing backing vocals, not to mention powerful singing by frontman Brendon Urie.
“Everyone I’ve ever loved is here within these walls / I’m sorry secret siren, but I’m blocking out your calls / I’ve had my adventure / I don’t need something new / I’m afraid of what I’m risking if I follow you / Into the unknown,” Urie belts.
Watch the lyric video for Panic’s rendition of ‘Into The Unknown’ below.
Disney has yet to release the full movie version as performed by Idina Menzel, who voices Elsa, and Norwegian singer Aurora. Hear a snippet of their version here:
Panic! At The Disco also posted behind-the-scenes photos of the studio session where they recorded ‘Into The Unknown’.
Besides Panic! At The Disco, Weezer and Kacey Musgraves will also put their own spin on songs from Frozen 2. Weezer will cover ‘Lost In The Woods’ while Musgraves will take on ‘All Is Found’. Their renditions will play during the end credits of the movie, which arrives in theatres November 22. Tickets to Frozen 2 in the US went on sale yesterday (November 4).


Twisted Documentation
Introduction
Executive summary
Graphical Overview
Twisted Internet
Tutorials
Writing a TCP server
Writing a TCP client
Getting Connected with Endpoints
Setting up the TwistedQuotes application
Designing a Twisted application
Tutorial: Twisted From Scratch
The Evolution of Finger: building a simple finger service
The Evolution of Finger: adding features to the finger service
The Evolution of Finger: cleaning up the finger code
The Evolution of Finger: moving to a component based architecture
The Evolution of Finger: pluggable backends
The Evolution of Finger: a clean web frontend
The Evolution of Finger: Twisted client support using Perspective Broker
The Evolution of Finger: using a single factory for multiple protocols
The Evolution of Finger: a Twisted finger client
The Evolution of Finger: making a finger library
The Evolution of Finger: configuration and packaging of the finger service
Using SSL in Twisted
Test-driven development with Twisted
Low-Level Networking and Event Loop
Reactor basics
UDP Networking
Using processes
Using Deferreds
Generating deferreds
Deferreds in depth
Scheduling
Using threads
Producers and Consumers: Efficient High-Volume Streaming
Choosing a reactor and GUI toolkit integration
High-Level Twisted
Helper programs and scripts (twistd, ..)
Twisted's plugin architecture
Writing Twisted Application Plugins for twistd
Interfaces and Adapters (Component Architecture)
Cred: Pluggable Authentication
Using the Twisted Application Framework
Utilities
Parsing command-lines
Logging
Using Dirdbm: Directory-based Storage
Using telnet to manipulate a twisted server
Tips for writing tests for Twisted code using Trial
Upgrading Applications
Twisted RDBMS support
Twisted RDBMS support with adbapi
The row database abstraction
Perspective Broker
Twisted Spread
Introduction to Perspective Broker
Using Perspective Broker
Managing Clients of Perspectives
Passing Complex Types
Authentication with Perspective Broker
PB Limits
Appendix
Glossary
Tips for debugging with emacs


The next generation may never see the Amazon rainforest, coral reefs, or a polar bear.
But the spectacular biodiversity existing on our planet, our home, is more than just beautiful,
it is what keeps us alive. Our destruction of ecological life support systems will literally kill us all.
We urgently need more countries to stand up to protect their people, animals, and OUR planet.
While there’s no information yet as to when the Equality Act will go before the Senate for a vote,
we do know this: Politicians need votes to stay in office. Votes come from the people.
Pressure from massive amounts of people is a major way to push politicians towards positive change.
LONDON, ENGLAND - DECEMBER 03: Green Party MP Caroline Lucas, (C), Labour MP Chuka Umunna (L)
and Conservative MP Justine Greening (R) join members of the 'Independent and the Peoples Vote campaign group',
to hand in a petition.
to Downing Street calling for the public to be given a chance to reject the final Brexit deal
in favour of staying in the EU,
LONDON, ENGLAND - FEBRUARY 26: Protesters for a change in Northern Irish law on abortion
remove petitions from suitcases outside the Northern Ireland Office at Parliament Square on February 26, 2019
in London, England.
Each protester with Amnesty International carried a suitcase containing sheets of paper with the names of 62,000 people


Common
MQTT Settings
Debug
MTRF64 device
Device List
add
Type
Channel
Protocol
Name
Description
Link
Use for input
Use for output
Notes
DebugLog


You tend to be more extroverted, courageous, and confident.
Actions are important to you, more so than words; you tend to have strong survival instincts.
You tend to be more ambitious and competitive compared to others. You are in it to win it.
You are more reliable and trustworthy although it is not as easy for you to trust others until you are very sure about them.
You put more thought into your actions and what you say instead of acting impulsively.
You are genuine and feel a deep need for inner peace and harmony.
Even though you are a fun and delightful person to be around, you are your harshest critic.
You tend to be impulsive, but surround yourself with a selective group of friends rather than a crowd of many.
You are more creative and imaginative. You love to dream big.
As cliché as it sounds, you tend to be a down-to-earth person that loves nature.
You are kind and compassionate to others and someone that others want to have around in any crisis.
You strive for balance and tend to wear your heart on your sleeve.
You are more inclined to listen to your gut and have a strong emotional sense, resilient.
You tend to be more optimistic and a motivator for others.

You tend to be more sensitive, compassionate, and understanding of others.
You have a peaceful nature to yourself even though what others say may be hurtful to you, you do not show it to others.
You are usually more introverted however you possess charismatic qualities as well.
What is your favorite color?


--- layout: post title: Why on earth do you search instead of typing the URL? ---
I've got absolutely no idea what to write about.
— Basile Simon (@basilesimon) November 15, 2013
Yes, that happens sometimes. I needed to find a story to write about, and as a result of such a common quest I found myself wandering on Google Trends. And I found something quite peculiar.
I opened the 'Explore' page, desperate enough to see what other people were looking.
What a surprise:
This basically means that a huge majority (I can't overstate it) of internet users search for a page instead of going to the page, even if they know its adress. Yes, I am in shock. I thought that only my grandmother was doing it.

And yes, people still do that in 2013. Progress, you said?
However, this weird interaction could be explained by the merging of the address bar and the search bar. I personally do not use the search box anymore, since Chrome introduced its "omnibox" in 2008, following the announcement of an "awesome box" for Firefox 3.
Still, all the modern browsers offer autocompletion - meaning that after visiting facebook.com, beginning to type "fac" in your adress bar will propose you "facebook.com" and a direct access to the page. As a result of the autocompletion it was feared in 2008 that the search traffic would die:
A potential issue with the address bar, for Mozilla, is that it decreases users' reliance on the search bar.
— Rafe Needleman on CNet, 14 May, 2008
It did not happen, as far as I know.
Still, I am confused by such irrational behaviours.


Here, we gonna discuss regarding the python datatypes and variables.
Function is nothing but a block of code that helps to perform operations on data.
Another way of defining the same, function is a set of instructions or lines of code that helps to perform repetative task or same operation on multiple data
There are 2 types of functions in Python
print() / len() / sqrt() / cbrt() and many more ....
Method is nothing but a block of code that helps to perform operations on data.
Another way of defining the same, method is a set of instructions or lines of code that helps to perform repetative task or same operation on multiple data
When we wrap function inside class then that function become methodThere are 3 types of Methods in Python
The instance method takes self
as first argument.
Instance method can access and modify the object (instance of class) state.
No decorators are needed for defining instance method
The class method takes cls (class)
as first argument.
Class method can access and modify the class state.
The class method takes the class as parameter to know about the state of that class as first argument.
@classmethod
decorator is used here.
The static method does not take any specific parameter.
Static Method cannot access or modify the class state.
Static methods do not know about class state. These methods are used to do some utility tasks by taking some parameters.
@staticmethod
decorator is used here.
staticmethod()
function can also be used to covert any function to static.
def
keyword to define any function or methodparanthesis ()
()
with name at the time of calling function


Double-click on a chart to zoom in. Hold down the shift key and double-click to zoom out.
Stack Charts
Use the "Open File(s)" button above to read local files into this web page for analysis. The files must be stored in either the ORNL JSON or CSV formats. Once read, the files can be selected from the middle select component. The "Redraw" button can be used to redraw the charts if the window is resized. Chart settings can be modified using the "Settings" dialog.


Let's share something About My Art..!
___________
__________
______________
Artist
*****************
+91-9319385744
swethachristuraja@gmail.com


i18n
Internationalization API
Changes from 0.4.0 to 0.4.1
- Supported Crystal versions of >= 0.35
- add Backend::Yaml#exists? to check whether given translation key exists
- add I18n.exists?
- add docs to I18n module public methods (most of wording was taken from the ruby I18n repo)
- Fixed the iter argument in
translate
to properly return the correct index
Example
# Array we are looking into ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
I18n.translate("__formats__.date.day_names", iter: 2) # Returns "Wednesday"
Breaking changes from 0.3 to 0.4
- Pluralization rules are now fully suites CLDR convention. Specifically
en
pluralization no more returnszero
Breaking changes from 0.2 to 0.3
- The first day of the week is now Monday according to ISO 8601.
- The nil value in
month_names
andabbr_month_names
was removed.
Installation
Add this to your application's shard.yml
:
dependencies:
i18n:
github: crimson-knight/i18n.cr
Usage
I18n.translate(
"some.dot.separated.path", # key : String
{attr_to_interpolate: "a"}, # options : Hash | NamedTuple? = nil
"pt", # force_locale : String = nil
2, # count : Numeric? = nil
"default translation", # default : String? = nil
nil # iter : Int? = nil
)
I18n.localize(
Time.utc_now, # object : _
"pt", # force_locale : String = I18n.config.locale
:time, # scope : Symbol? = :number
"long" # format : String? = nil
)
Arguments interpolation
Translation may include argument interpolation. For doing this use regular crystal named interpolation placeholder and pass hash or named tuple as a options
argument:
message:
new: "New message: %{text}"
# New message: hello
I18n.translate("message.new", {text: "hello"})
I18n.translate("message.new", {:text => "hello"})
I18n.translate("message.new", {"text" => "hello"})
Also any extra key-value pair will be ignored and missing one will not cause any exception:
I18n.translate("message.new", {message: "hello"}) # New message: %{text}
Configuration
require "i18n"
I18n.load_path += ["spec/locales"]
I18n.init # This will load locales from all specified locations
I18n.default_locale = "pt" # default can be set after loading translations
There is a handler for Kemalyst that bring I18n configuration.
Note on YAML Backend
Putting translations for all parts of your application in one file per locale could be hard to manage. You can store these files in a hierarchy which makes sense to you.
For example, your config/locales directory could look like this:
locales
|--defaults
|----en.yml
|----pt.yml
|--models
|----en.yml
|----pt.yml
|--views
|----users
|------en.yml
|------pt.yml
This way you can separate model related translations from the view ones. To require all described subfolders at once use **
- I18n.load_path += ["locals/**/"]
Date/Time Formats
To localize the time (or date) format you should pass Time
object to the I18n.localize
. To pick a specific format path format
argument:
I18n.localize(Time.local, scope: :date, format: :long)
By defaultTime
will be localized with:time
scope.
To specify formats and all need localization information (like day or month names) fill your file in following way:
NOTE: According to ISO 8601, Monday is the first day of the week
__formats__:
date:
formats:
default: '%Y-%m-%d' # is used by default
long: '%A, %d de %B %Y'
month_names: # long month names
- Janeiro
- Fevereiro
- Março
- Abril
- Maio
- Junho
- Julho
- Agosto
- Setembro
- Outubro
- Novembro
- Dezembro
abbr_month_names: # month abbreviations
- Jan
- Fev
# ...
day_names: # fool day names
- Segunda
# ...
abbr_day_names: # short day names
- Seg
# ...
Format accepts any crystal Time::Format
directives. Also following directives will be automatically localized:
| Directive | Description | Key |
|---|---|---|
| %a
| short day name | date.abbr_day_names
|
| %A
| day name | date.day_names
|
| %b
| short month name | date.abbr_month_names
|
| %B
| month name | date.month_names
|
| %p
| am-pm (lowercase) | time.am
/time.pm
|
| %P
| AM-PM (uppercase) | time.am
/time.pm
|
Pluralization
In many languages — including English — there are only two forms, a singular and a plural, for a given string, e.g. "1 message" and "2 messages". Other languages (Arabic, Japanese, Russian and many more) have different grammars that have additional or fewer plural forms.
The count
interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined by CLDR:
message:
one: "%{count} message"
other: "%{count} messages"
I18n.translate("message", count: 1) # 1 message
I18n.translate("message", count: 2) # 2 messages
I18n.translate("message", count: 0) # 0 messages
count
should be passed as argument - not inside ofoptions
. Otherwise regular translation lookup will be applied.
I18n defines default CLDR rules for many locales (see src/i18n/config/plural_rules
), however they can be overwritten:
I18n.plural_rules["ru"] = ->(n : Int32) {
if n == 0
:zero
elsif ((n % 10) == 1) && ((n % 100 != 11))
# 1, 21, 31, 41, 51, 61...
:one
elsif ([2, 3, 4].includes?(n % 10) && ![12, 13, 14].includes?(n % 100))
# 2-4, 22-24, 32-34...
:few
elsif ((n % 10) == 0 || ![5, 6, 7, 8, 9].includes?(n % 10) || ![11, 12, 13, 14].includes?(n % 100))
# 0, 5-20, 25-30, 35-40...
:many
else
:other
end
}
kid:
zero: 'нет детей'
one: '%{count} ребенок'
few: '%{count} ребенка'
many: '%{count} детей'
other: '%{count} детей'
I18n.locale = "ru"
I18n.translate("kid", count: 0) # нет детей
I18n.translate("kid", count: 1) # 1 ребенок
I18n.translate("kid", count: 2) # 2 ребенка
I18n.translate("kid", count: 6) # 6 детей
Iteration
To store several alternative objects under one localization key they could be just listed in the file and later retrieved using iter
argument:
NOTE : The first index is 0
__formats__:
date:
day_names: [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]
I18n.translate("__formats__.date.day_names", iter: 2) # >>> "Wednesday"
Embedding translations inside your binary
You can embed translations inside your binary by using the following macro call:
I18n::Backend::Yaml.embed(["some/locale/directory", "some/other/locale/directory"])
Development
TODO :
- [ ] Add more backends ( Database, json based, ruby based ( why not ? ))
- [ ] others ( there is always something to add ... or remove )
Contributing
- Fork it ( https://github.com/crimson-knight/i18n/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- [crimson-knight Seth Tucker (New owner as of July 2021)
- [imdrasil Roman Kalnytskyi
Inspiration taken from:
- https://github.com/whity/crystal-i18n
- https://github.com/mattetti/i18n
Special thank you to [TechMagister for being the original owner and creator of this shard.


Here are a few projects I've recently worked on during my course with MIT
A simple exercise in DOM manipulation. Click the link below to check out the project in action!
An exercise in recursion, this project moves a map marker through a bus route. To run the project, click the link below, and once on the new page, click "Show Stops Between MIT and Harvard"
A simple game made to exercise DOM manipulation. To run the project, click the link below, click "Add PacMan" as many times as you want, and then click "Start Game"


England to wear black armbands in tribute to Bob Willis
by Press AssociationEngland players will wear black armbands during the first Test of their tour of South Africa in honour of former bowler Bob Willis.
Willis, who captained England before turning to punditry after retirement in 1984, died last week at the age of 70.
The England and Wales Cricket Board announced its plans to pay tribute to England's fourth highest wicket-taker of all time at SuperSport Park in Centurion later this month.
An ECB spokesperson said: "The team will wear black armbands in the first Test in South Africa as a tribute to Bob Willis."
The first Test begins on Boxing Day as part of a four-match series against the Proteas, followed by three one-day internationals and three T20 clashes.


Nightly Brief
by CNSYour Friday night briefing from the staff of Courthouse News
Top CNS stories for today including a new transcript from impeachment investigators quotes the acting White House Chief of Staff as saying Ukraine would have to open investigations sought by President Donald Trump as a condition for Ukraine’s president getting a White House visit; Alan Dershowitz brought counterclaims against the prominent lawyer for two of Jeffrey Epstein’s accusers before the ink on the lawyer’s defamation suit was even dry; The United Nations’ highest court ruled that it has jurisdiction to hear claims that Russia illegally financed separatist groups in eastern Ukraine, and more.
Sign up for CNS Nightly Brief, a roundup of the day’s top stories delivered directly to your email Monday through Friday.
National
1.) A new transcript released Friday from impeachment investigators quotes Mick Mulvaney, the acting White House Chief of Staff, as saying Ukraine would have to open investigations into former Vice President Joe Biden, his son and the 2016 presidential election as a condition for Ukraine’s president getting a White House visit.
2.) Alan Dershowitz brought counterclaims against the prominent lawyer for two of Jeffrey Epstein’s accusers before the ink on the lawyer’s defamation suit was even dry.
3.) The Supreme Court agreed Friday to hear a case that will decide whether companies with “.com” or other domains in their names can receive federal trademark protection, even if their names would otherwise be generic.
4.) Steve Bannon testified in Washington, D.C. federal court Friday that Roger Stone was the Trump campaign’s only inroad to WikiLeaks during the 2016 presidential election.
International
5.) On an airplane trip back to Paris from a visit to French islands in the Indian Ocean, Emmanuel Macron did something no other French president has done: He let himself be interviewed by a journalist with Valeurs Actuelles, a magazine long associated with France’s ultra-conservative wing.
6.) In a big win for Ukraine, the United Nations’ highest court ruled Friday that it has jurisdiction to hear Kiev’s claims that Russia illegally financed separatist groups in eastern Ukraine.
Regional
7.) In his latest dispatch, Courthouse News’ western bureau chief communes with the sun and fog on the California coast.
8.) The GOP-controlled Wisconsin Legislature quickly shut down a special floor session meant to debate gun reform, fulfilling a promise made almost immediately after the session was called by the Democratic governor.
Copyright © 2019 courthousenews.com


Conspiracy charges dropped in Michael Avenatti Nike case
by KNOENEW YORK (AP) — An indictment charging California attorney Michael Avenatti with conspiring to extort Nike has been rewritten to drop two conspiracy counts.
In a tweet, Avenatti said he was “extremely pleased” and expects eventually to be “fully exonerated.”
The refreshed indictment returned Wednesday in Manhattan federal court adds an honest services wire fraud charge.
Avenatti has pleaded not guilty to charges he committed extortion by threatening to publicly reveal dirty dealings by Nike in college athletics if he wasn’t paid up to $25 million.
Avenatti also faces fraud charges in Los Angeles federal court and in a separate New York case after he was charged with cheating porn star Stormy Daniels of book deal income. Avenatti once represented Daniels over a nondisclosure deal regarding an alleged affair with President Donald Trump.
Copyright 2019 Associated Press. All rights reserved.


Methods
(static) merge(Validation) → {Validation}
Merges a list of validations, cascading conflicting field errors
from the end of the array to the beginning.
This operation does not modify any input validations. It creates a
new validation which contains the combined information from all
input validations.
Parameters:
| Name | Type | Description |
|---|---|---|
Validation |
Validation | to merge. |
- Source:
Returns:
- Type
- Validation
addError(fieldName, error) → {Validation}
Stores an error message for a field, categorized by the field name.
Parameters:
| Name | Type | Description |
|---|---|---|
fieldName |
string | Name of the field. |
error |
string | Error message. |
- Source:
Returns:
- Type
- Validation
errorFieldNames() → {Array.<string>}
Retrieves the list of error field names. Returns
an empty array if no errors are stored.
- Source:
Returns:
- Type
- Array.<string>
errors(fieldName) → {Array.<string>}
Retrieves the list of errors stored for a field name. Returns
an empty array if no errors are stored.
Parameters:
| Name | Type | Description |
|---|---|---|
fieldName |
string | Name of the field. |
- Source:
Returns:
- Type
- Array.<string>
merge(Validation) → {Validation}
Merges two validations. If both validations contain errors for
the same field, the second validation's errors will overwrite the
first.
This operation does not modify either validation. It creates a
new validation which contains the combined information from both
input validations.
Parameters:
| Name | Type | Description |
|---|---|---|
Validation |
Validation | to merge. |
- Source:
Returns:
- Type
- Validation
succeeded() → {Boolean}
Determines if the validation succeeded.
- Source:
Returns:
- Type
- Boolean


make
Task runner for targets described in Makefile.
Mostly used to control the compilation of an executable from source code.
More information: home page
- Call the first target specified in the Makefile (usually named "all"):
make
- Call a specific target:
make target
- Call a specific target, executing 4 jobs at a time in parallel:
make -j4 target
- Use a specific Makefile:
make --file path/to/file
- Execute make from another directory:
make --directory path/to/directory
- Force making of a target, even if source files are unchanged:
make --always-make target
- Override a variable defined in the Makefile:
make target variable=new_value
- Override variables defined in the Makefile by the environment:
make --environment-overrides target


{% extends 'base.html' %} {% block title %} Change Password Complete {% endblock %} {% block body %}
Your password has been successfully updated.
Back to your account?


Curiosity
Home
Documentation
Updates
Support
Add
Home
Documentation
Updates
About
Curious
to find out about this amazing bot?
Life get's guided by Curiosity !
Under Construction for version 3.0
Get started now
Discord
GitHub
Twitter


By default, each class will serve the path built from its underscored name.
Ex.: Forum
will serve "/forum", LatestNews
will serve "/latest_news" etc.
This can be changed by setting base URL via map
.
Example: - Book
app should serve "/books"
class Book < E map '/books' # ... end
[ contents ↑ ]
Lets say you need your News
app to serve both "/news" and "/headlines" base URLs.
It is easily done by using map
with multiple params.
First param will be treated as base URL, any other consequent params - as canonical ones.
Example: - News
should serve both "/news" and "/headlines" paths.
class News < E map :news, :headlines def index # ... end end
To find out either current URL is a canonical URL use canonical?
It will return nil
for base URLs and a string for canonial ones.
Example:
class App < E map '/', '/cms' def page # on /page canonical? == nil # on /cms/page canonical? == "/page" end # ... end
[ contents ↑ ]
Defining Espresso actions is as simple as defining Ruby methods,
cause Espresso actions actually are pure Ruby methods.
Example: - Defining 2 actions - :index and :edit
class App < E map '/' def index # ... end def edit # ... end end # Now `App` will now serve: # - / # backed by `:index` action # - /edit # backed by `:edit` action
[ contents ↑ ]
Usually actions should also contain non-alphanumeric chars.
Most common - hyphens, dots and slashes.
To address this, Espresso uses a map to translate action names into HTTP paths.
The default map looks like this:
"__" => "/" "___" => "-" "____" => "."
Example:
def users__online # 2 underscores # ... end # will serve users/online def latest___news # 3 underscores # ... end # will serve latest-news def read____html # 4 underscores # ... end # will serve read.html
You can define your own rules by using path_rule
at class level.
Example: - Convert bang methods into .html suffixed paths
class App < E map '/' path_rule "!", ".html" def news! # ... end end # :news! action will serve /news.html path
Example: - Convert methods ending in "_j" into .json suffixed paths
class App < E map '/' path_rule /_j$/, ".json" def j_news # ... end end # :news_j action will serve /news.json path
[ contents ↑ ]
Though path rules are useful enough, you can bypass them and set routes directly.
Example: make bar
method to serve /bar
, /some/url
and /some/another/url
def bar map '/' # ... end alias_action 'some/url', :bar alias_action 'some/another/url', :bar
Example: make foo
method to serve /foo
and /some/url
via any request method
def foo map '/' # ... end alias_action 'some/url', :foo
Example: get_foo
method will serve /foo
and /some/url
only via GET
request method
def get_foo map '/' # ... end alias_action 'some/url', :get_foo
Also standard Ruby alias
can be used:
class App < E map '/' def news # ... end alias news____html news alias headlines__recent____html news end
Now news
action will serve any of:
NOTE: Private and protected methods usually are not publicly available via HTTP.
However, if you add an action alias to such a method, it becomes public via its alias.
To alias a private/protected method and keep it private,
use standard ruby alias
or alias_method
rather than alias_action
.
[ contents ↑ ]
Espresso will split URL by slashes and feed obtained array to the Ruby method that backing current action.
Let's suppose we have an action like this:
class App < E map '/' def read type, status # ... end end
If we do a request like this - "/read/news/latest", it will be decomposed as follow:
Now Espresso will split params and call action:
read "news", "latest"
Current example will work just well, cause read
receives as many arguments as expected.
Now let's suppose we do an request like: "/read/news"
This wont work, cause read
receives 1 argument instead of 2 expected.
read "news"
And "/read/news/articles/latest" wont work either, cause read
receives too many arguments.
read "news", "articles", "latest"
However, as we know, Ruby is powerful enough.
And Espresso uses this power in full.
So, when we need read
method to accept 1 or 2 args,
we simply give the last param a default value:
class App < E map '/' def read type, status = 'latest' # ... end end
Now read
action will serve "/read/news" as well as
"/read/news/latest", "/read/news/archived", "/read/news/anything!"
Also we can make "/read/news/articles/latest" to work.
class App < E map '/' def read *types, status # ... end end
That's it! Now when calling "/read/news/articles/latest",
types
will be an array like ["news", "articles"] and status will be equal to "latest".
In a word, if Ruby method works with given params, HTTP action will work too.
Otherwise, HTTP action will return "404 NotFound" error.
[ contents ↑ ]
format
allow to manipulate routing by instructing actions to respond to various extensions.
Also it is aimed to automatically set Content-Type
header based on used extension.
Example:
class App < E map '/' format '.xml' def article # ... end end
In the example above, article action will respond to both "/article" and "/article.xml" URLs.
format
accepts any number of extensions.
The second meaning of format
is to automatically set Content-Type header.
Content type are extracted from Rack::Mime::MIME_TYPES
map.
Ex: format '.txt'
will return the content type extracted via Rack::Mime::MIME_TYPES.fetch('.txt')
Worth to note that format
will act on all actions.
To set format(s) only for specific actions, use format_for
.
Example: - only pages
action will respond to URLs ending in .html and .xml
class App < E map '/' format_for :pages, '.xml', '.html' def pages # ... end def news # ... end # ... end
Now App will respond to any of "/pages", "/pages.html", "/pages.xml" and "/news" but not "/news.html" nor "/news.xml", cause format was set for pages
action only.
It is also possible to disable format for specific actions by using disable_format_for
:
class App < E map '/' format '.xml' # this will enable .xml format for all actions disable_format_for :news, :pages # disabling format for :pages and :news actions # ... end
Worth to note that Espresso will get rid of extension passed with last param,
so you get clean params without manually remove format.
Meant that when "/news/100.html" requested, you get "100" param inside news
action, rather than "100.html"
Example:
class App < E format '.xml' def read item = nil # on /read item == nil # on /read.xml item == nil # on /read.xml/book 404 NotFound # on /read/book item == "book" # on /read/book.xml item == "book" # on /read/100.xml item == "100" # on /read/blah.xml item == "blah" # on /read/blah.json item == "blah.json" end end
/read.xml will return XML Content-Type /read/book.xml will return XML Content-Type too /read/100.xml will return XML Content-Type as well /read/anything-here.xml will return XML Content-Type either /read instead will return default Content-Type /read/book will return default Content-Type too
[ contents ↑ ]
By default, verbless actions will respond to any request method.
Example: - index
action responding to any request method
class App < E def index end end
To make an action to respond only to a specific request method, simply prepend desired request method verb to action name.
Example:
class App < E def post_news # will serve POST /news # ... end def put_news # will serve PUT /news # ... end # etc. end
IMPORTANT: verbified actions has priority over verbless ones, regardless definition order!
That's it, if you have news
and post_news
actions, on POST requests post_news
will be executed:
class App < E def post_news # will serve POST requests # ... end def news # will serve any requests except POST ones # ... end end
[ contents ↑ ]
Espresso uses a really flexible rewrite engine that allow to redirect the browser to new address as well as pass control to arbitrary controller(without redirect) or just send a custom response to browser(without redirect as well).
A rewrite rule consist of a regular expression and a block that receives matches via arguments.
redirect
and permanent_redirect
will redirect browser to new address with 302 and 301 codes respectively.
Example:
app = EspressoApp.new do rewrite /\A\/(.*)\.php\Z/ do |title| redirect Cms.route(:index, title) end # ... end
pass
will pass control to an arbitrary controller, without redirect.
Example:
class Articles < E def read title # ... end end class Pages < E def archive title # ... end end app = EspressoApp.new do # pass old pages to archive action rewrite /\A\/(.*)\.php\Z/ do |title| pass Pages, :archive, title end # pages ending in html are in fact articles, so passing control to Articles controller rewrite /\A\/(.*)\.html\Z/ do |title| pass Articles, :read, title end end
halt
will send response to browser and stop any code execution, without redirect.
It accepts from 0 to 3 arguments.
If argument is a hash, it is added to headers.
If argument is a Integer, it is treated as Status-Code.
Any other arguments are treated as body.
If a single argument given and it is an Array, it is treated as a bare Rack response and instantly sent to browser.
Example:
app = EspressoApp.new do rewrite /\A\/archived\/(.*)\.html\Z/ do |title| unless page = Model::Page.first(:url => title) halt 404, 'page not found' end halt page.content, 'Last-Modified' => page.last_modified.to_rfc2822 end end
[ contents ↑ ]


This is a post.
2015-01-02 03:04
(updated:
05:06
)
Explanation: this is to test for the behaviour described
here
.


I live in Incline Village, NV and have been here for three years after moving from Sacramento, CA. In acramento, we raised our son, Conner, who graduated from Cal in 2019 and now works as a software engineeer at Amazon in Seattle.
I have a passion for anything outdoors; snowshoeing, snowskiing, watersking, wakeboarding, surfing, mountain biking, and most recently, kite surfing.
In 2017, I sold two companies for applications we created on Salesforce. These applicationss accelereated the recruitment and placement of clinical contongent labor (nurses and allied health workers) and I now work as the CIO for the larger parent company, and also lead StaffBot; the now independent company that creates software in the healthcare space.


11 June 2007
The Egyptian Ministry of Health and Population has confirmed a new human case of avian influenza A(H5N1) virus infection. The case has been confirmed by the Egyptian Central Public Health Laboratory and by the US Naval Medical Research Unit No.3 (NAMRU-3).
The case is a 10 years old female from Qena Governorate. She developed symptoms on 1 June, was admitted to hospital on 6 June and died on 9 June. Initial investigations into the source of her infection indicate exposure to dead birds.
Of the 35 cases confirmed to date in Egypt, 15 have been fatal.


License
This documentation and the code samples are licensed under the Apache license 2.0:
Copyright 2007 Steven Devijver
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2007, Steven Devijver
This help file has been generated by the freeware version of HelpNDoc


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Any, Callable, Generator, Iterable, List, Mapping, Optional, Sized
from pathos.helpers import cpu_count
from pathos.multiprocessing import ProcessPool as Pool
from tqdm.auto import tqdm
__author__ = "Christian Heider Nielsen"
__all__ = [
"parallel_map",
"parallel_imap",
"parallel_umap",
"parallel_uimap",
"sequential_map",
"sequential_imap",
]
__doc__ = (
r"""Map functions with tqdm progress bars for parallel and sequential processing."""
)
def _sequential(
function: Callable,
*iterables: Iterable,
func_kws: Optional[Mapping] = None,
**kwargs: Any
) -> Generator:
"""Returns a generator for a sequential map with a progress bar.
Arguments:
function(Callable): The function to apply to each element of the given Iterables.
iterables(Tuple[Iterable]): One or more Iterables containing the data to be mapped.
Returns:
A generator which will apply the function to each element of the given Iterables
sequentially in order with a progress bar."""
# Determine length of tqdm (equal to length of shortest iterable)
length = min(len(iterable) for iterable in iterables if isinstance(iterable, Sized))
# Create sequential generator
for item in tqdm(map(function, *iterables, **func_kws), total=length, **kwargs):
yield item
def _parallel(
ordered: bool,
function: Callable,
*iterables: Iterable,
func_kws: Optional[Mapping] = None,
num_cpus: Optional[int] = None,
**kwargs: Any
) -> Generator:
"""Returns a generator for a parallel map with a progress bar.
Arguments:
ordered(bool): True for an ordered map, false for an unordered map.
function(Callable): The function to apply to each element of the given Iterables.
iterables(Tuple[Iterable]): One or more Iterables containing the data to be mapped.
Returns:
A generator which will apply the function to each element of the given Iterables
in parallel in order with a progress bar."""
if func_kws is None:
func_kws = {}
if num_cpus is None: # Determine num_cpus
num_cpus = cpu_count()
elif type(num_cpus) == float:
num_cpus = int(round(num_cpus * cpu_count()))
# Determine length of tqdm (equal to length of shortest iterable)
length = min(len(iterable) for iterable in iterables if isinstance(iterable, Sized))
map_type = "imap" if ordered else "uimap"
pool = Pool(num_cpus) # Create parallel generator
map_func = getattr(pool, map_type)
for item in tqdm(
map_func(function, *iterables, (list(func_kws.values()),) * length),
total=length,
**kwargs
):
yield item
pool.clear()
[docs]def parallel_imap(function: Callable, *iterables: Iterable, **kwargs: Any) -> Generator:
"""Returns a generator for a parallel ordered map with a progress bar."""
return _parallel(True, function, *iterables, **kwargs)
[docs]def parallel_map(function: Callable, *iterables: Iterable, **kwargs: Any) -> List[Any]:
"""Performs a parallel ordered map with a progress bar."""
return list(parallel_imap(function, *iterables, **kwargs))
[docs]def parallel_uimap(
function: Callable, *iterables: Iterable, **kwargs: Any
) -> Generator:
"""Returns a generator for a parallel unordered map with a progress bar."""
return _parallel(False, function, *iterables, **kwargs)
[docs]def parallel_umap(function: Callable, *iterables: Iterable, **kwargs: Any) -> List[Any]:
"""Performs a parallel unordered map with a progress bar."""
return list(parallel_uimap(function, *iterables, **kwargs))
[docs]def sequential_imap(
function: Callable, *iterables: Iterable, **kwargs: Any
) -> Generator:
"""Returns a generator for a sequential map with a progress bar."""
return _sequential(function, *iterables, **kwargs)
[docs]def sequential_map(
function: Callable, *iterables: Iterable, **kwargs: Any
) -> List[Any]:
"""Performs a sequential map with a progress bar."""
return list(sequential_imap(function, *iterables, **kwargs))
if __name__ == "__main__":
def asdasd() -> None:
"""
:rtype: None
"""
def add(a, b, *c):
"""description"""
return a + b
print(
parallel_map(
add, ["1", "2", "3"], ["a", "b", "c"], func_kws={"k": "sdafasd"}
)
)
asdasd()


Jeremy Corbyn reveals he'll remain 'neutral' in second Brexit referendum
Jeremy Corbyn says he will adopt a ‘neutral stance’ in a second Brexit referendum.
The Labour leader was the first to be grilled by voters during a special episode of BBC’s Question Time.
Mr Corbyn was quizzed over fears for businesses, anti-Semitism, misogyny, freedom of speech and his support of ousted Bolivia president Evo.
When asked how he would campaign if he wins next month’s election, he said he would start by negotiating a ‘credible’ Leave deal before he was interrupted by groans from sections of the audience.
Advertisement Advertisement
However, making his clearest comments to date on the issue, he continued: ‘My role and the role of our government will be to ensure that that referendum is held in a fair atmosphere and we will abide by the result of it.
‘And I will adopt, as prime minister, if I am at the time, a neutral stance so that I can credibly carry out the results of that to bring communities and country together rather than continuing an endless debate about the EU and Brexit.’
Mr Corbyn began his slot on the defensive, asked whether businesses ‘should be frightened of an incoming Labour government’.
But he argued only the ‘biggest businesses will be asked to pay a little more’ in corporation tax, but added the level will be lower than that in 2010.
He also fended off an angry audience member who declared ‘freedom would be completely eroded’ if he got the keys to Number 10.
‘I have spent my life getting into hot water for defending people because I believed their human rights should not be violated and that’s the kind of government that I intend to lead,’ Mr Corbyn said.
Another confronted him about sexism and anti-Semitism faced by his MPs – in particular Ruth Smeeth, who is Jewish – saying he does not ‘buy this nice old grandpa’ image.
Advertisement Advertisement
‘Nobody should suffer any abuse in public life or privately,’ he replied.
‘Many women Labour MPs, Ruth Smeeth included and others, have suffered the most unbelievable levels of abuse.’
He then reminded the audience ‘it was a Labour MP, Jo Cox, who was murdered because she stood up in public life’.
‘I simply say to you that bad behaviour, misogynism, racism in any form is absolutely not acceptable in any form whatsoever in my party or in society,’ Mr Corbyn added.
Got a story for Metro.co.uk?
Get in touch with our news team by emailing us at<EMAIL_ADDRESS>For more stories like this, check our news page.


---
layout: default
published: true
---
{% include carousel.html %}
{% for post in site.posts limit:3 %}
-
{{ post.date | date: "%b %-d, %Y" }}
{{ post.excerpt}}
{% endfor %}
Show all news...
Key Inclusion Criteria:
- Age: ≥18 to ≤75 years
- Acute stroke syndrome due to a spontaneous ICH
- Haemorrhage into basal ganglia, or thalamus that may extend
into cerebral lobes, ventricles or subarachnoid space
- Glasgow coma scale (GCS) <14 and >7 at randomization
- NIHSS ≥10 and ≤30
- Surgical treatment within 72 hours after ictus
- Volume of hematoma ≥30ml and ≤100ml
Key Exclusion Criteria:
- Aneurysm, arteriovenous malformation, tumor, trauma, thrombolysis
- Cerebellar or brainstem hemorrhage
- Exclusive lobar hemorrhage
- Moribund patients (GCS 3-7)


from data: j.a is data (should be data)
from var: j.a is var (should be var)
from file: j.a is file (should be file)
from page: j.a is page (should be page)


eLearning System
Login
Sign Up
Contact Us
About Us
Submit
© Capstone CS- eLearning All rights reserved.


{% extends "layout_argleton.html" %} {% block page_title %} Argleton County Council - Apply for a resident's parking permit in Argleton {% endblock %} {% block content %} Enter vehicle details Enter the registration number of the vehicle you wish to get a permit for. Enter vehicle registration number Enter vehicle registration number Next {% endblock %}
Enter the registration number of the vehicle you wish to get a permit for.


Chapter 2 An introduction to hierarchical modeling
2.0.1 What is hierarchical modeling
Hierarchical modeling is the practice of building rich models, typcially in which each individual in your dataset has their own set of parameters. Of course, without good prior information, this might not be identified, or might be very weakly identified. Hierarchical modeling helps us deal with this problem by considering parameters at the low level as “sharing” information across individuals. This structure is known as “partial pooling”. This session covers partial pooling, starting from the canonical example “8 schools”, then shows how you can use partial pooling to provide prior information when combining previous studies with a new dataset. Finally I show how partial pooling can be used for analysis of panel data.
2.0.2 Why do hierarchical modeling?
There are a few excellent reasons to do hierarchical modeling:
To deal with unobserved information fairly fixed at the level of the group
The standard reason in economics to use panel data is to be able to “control for” confounding information that is fixed at the level of the individual over time. A similar motivation exists in hierarchical modeling.
The big difference is that we will not consider the individual or time effects to be fixed. Indeed, we routinely “shrink” effects towards a group-level average. This encodes the heuristic “death, taxes, and mean reversion”. Cross-validating your results will almost always show that such an approach is superior to fixed effects for prediction.
Prediction with high-dimensional categorical variables
Often in applied economics we have very high-dimensional categorical variables. For instance, plant, manager, project etc. This can massively increase the size of the parameter space, and result in over-fitting/poor generalization. In contrast, implementing high-dimensioned predictors as (shrunken) random effects typically results in large improvements in predictive power.
Mr P: Multi-level regression and post-stratification
As economists we want to make inferences, typically of a causal nature. A common problem is that our data are not collected randomly; we have some survey bias. Frequentists tend to correct for this by weighting observations according to the inverse of their probability of being observed. Yet this approach moves away from a generative model, making model comparison and validation difficult.
Mr P is the practice of fitting a model in which individuals, or groups of individuals (say, grouped by demographic cell) have their own sets of parameters (which are shrunk towards a hierarchical prior). When we want to make an inference for a new population we only need to know its demographics. The inference is the weighted average across effects in the sample, with weights coming from the new population.
This method has the advantage that we can work with highly-biased samples, while keeping within a generative framework (making Modern Statistical Workflow completely doable). In a notorious example, Mr P was used by David Rothschild at Microsoft Research to predict the outcome of the 2012 election based on a survey run through the Xbox platform. The survey was almost entirely young men.
2.0.3 Exchangeability
Astute readers familiar with fixed effects models will have noted a problem with one of my arguments above. I said that we could use random intercepts to soak up unobserved information that affects both \(X\) and \(y\) by including group-varying intercepts \(\alpha_{j}\). But this implies that the unobserved information fixed in a group, \(\alpha_{j}\), is correlated with \(X\). This correlation violates a very important rule in varying-intercept, varying-slope models: exchangeability.
Exchangeability says that there should be no information other than the outcome \(y\) that should allow us to distinguish the group to which a group-level parameter belongs.
In this example, we can clearly use values of X to predict \(j\), violating exchangeability. But all is not lost. The group-varying parameter needs not be uncorrelated with X, only the random portion of it.
2.0.4 Conditional exchangeability and the Bafumi Gelman correction
Imagine we have an exchangability issue for a very simple model with only group-varying intercept: the unobserved information \(\alpha_{j}\) is correlated with \(X_{i,j}\) across groups. Let’s break \(\alpha_{j}\) down into its fixed and random portions.
\[ \alpha_{j} = \mu_{1} + \eta_{j} \]
where \[ \eta_{j} \sim \mbox{normal}(0, \sigma_{\eta}) \]
So that now the regression model can be written as
\[ y_{i,t} = \mu_{1} + X_{i,j}\beta + e_{i,j} \mbox{ where } e_{i,j} = \epsilon_{i,j}+ \eta_{j} \]
For the correlation to hold, it must be the case that \(\eta_{j}\) is correlated with \(X_{i,j}\). But our regression error is \(e_{i,j}\), which is clearly correlated with \(X\) violating the Gauss-Markov theorem and so giving us biased estimates.
In a nice little paper Bafumi and Gelman suggest an elegant fix to this: simply control for group level averages in the model of \(\alpha_{j}\). This is a Bayesian take on what econometricians might know as a Mundlak/Chamberlain approach. If \(\bar{X}_{j}\) is the mean of \(X_{i,j}\) in group \(j\), then we could use the model
\[ \alpha_{j} = \hat{\alpha} + \gamma \hat{X}_{j} + \nu_{j} \]
which results in the correlaton between \(\nu_{j}\) and \(X_{i,j}\) across groups being 0. It’s straightforward to implement, and gets you to conditional exchangeability—a condition under which mixed models like this one are valid.
2.0.5 Exercise 1: Hierarchical priors
In this exercise we’ll estimate an experimental treatment effect using linear regression, while incorporating prior information from previous studies. Rather than doing this in stages (estimating the treatment effect and then doing some meta-analysis), we’ll do everything in one pass. This has the advantage of helping us to get more precise estimates of all our model parameters.
2.0.6 A very basic underlying model
Let’s say that we run the \(J\)’th experiment estimating the treatment effect of some treatment \(x\) on an outcome \(Y\). It’s an expensive and ethically challenging experiment to run, so unfortunately we’re only able to get a sample size of 20. For simplicity, we can assume that the treatment has the same treatment effect for all people, \(\theta\) (this is easily dropped in more elaborate analyses). There have been \(J-1\) similar experiments run in the past. In this example our outcome data \(Y\) are conditionally normally distributed with (untreated) mean \(\mu\) and standard deviation \(\sigma\). There is nothing to stop us from having a far more complex model for the data. So the outcome model looks like this:
\[ y_{i, J} \sim \mbox{Normal}(\mu + \theta_{J} x_{i,J}, \sigma) \]
The question is: how can we estimate the parameters of this model while taking account of the information from the \(J-1\) previous studies? The answer is to use the so-called hierarchical prior.
2.0.7 The hierarchical prior
Let’s say that each of the \(J-1\) previous studies each has an estimated treatment effect \(\beta_{j}\), estimated with some standard error \(se_{j}\). Taken together, are these estimates of \(\beta_{j}\) the ground truth for the true treatment effect in their respective studies? One way of answering this is to ask ourselves: if the researchers of each of those studies replicated their study in precisely the same way, but after checking the estimates estimated by the other researchers, would they expect to find the same estimate they found before, \(\beta_{j}\)? Or would they perhaps expect some other treatment effect estimate, \(\theta_{j}\), that balances the information from their own study with the other studies?
The answer to this question gives rise to the hierarchical prior. In this prior, we say that the estimated treatment effect \(\beta\) is a noisy measure of the underlying treatment effect \(\theta_{j}\) for each study \(j\). These underlying effects are in turn noisy estimates of the true average treatment effect \(\hat{\theta}\)—noisy because of uncontrolled-for varation across experiments. That is, if we make assumptions of normality:
\[ \beta_{j} \sim \mbox{Normal}(\theta_{j}, se_{j}) \]
and
\[ \theta_{j} \sim \mbox{Normal}\left(\hat{\theta}, \tau\right) \]
Where \(\tau\) is the standard devation of the distribution of plausible experimental estimates.
The analysis therefore has the following steps:
- Build a model of the treatment effects, considering our own study as another data point
- Jointly estimate the hyperdistribution of treatment effects.
As an example, we’ll take the original 8-schools data, with some fake data for the experiment we want to estimate. The 8-schools example comes from an education intervention modeled by Rubin, in which a similar experiment was conducted in 8 schools, with only treatment effects and their standard errors reported. The task is to generate an estimate of the possible treatment effect that we might expect if we were to roll out the program across all schools.
library(rstan); library(dplyr); library(ggplot2); library(reshape2)
# The original 8 schools data
schools_dat <- data_frame(beta = c(28, 8, -3, 7, -1, 1, 18, 12),
se = c(15, 10, 16, 11, 9, 11, 10, 18))
# The known parameters of our data generating process for fake data
mu <- 10
sigma <- 5
N <- 20
# Our fake treatment effect estimate drawn from the posterior of the 8 schools example
theta_J <- rnorm(1, 8, 6.45)
# Create some fake data
treatment <- sample(0:1, N, replace = T)
y <- rnorm(N, mu + theta_J*treatment, sigma)
The Stan program we use to estimate the model is below. Note that these models can be difficult to fit, and so we employ a “reparameterization” below for the theta
s. This is achieved by noticing that if
\[ \theta_{j} \sim \mbox{Normal}\left(\hat{\theta}, \tau\right) \] then \[ \theta_{j} = \hat{\theta} + \tau z_{j} \]
where \(z_{j}\sim\mbox{Normal}(0,1)\). A standard normal has an easier geometry for Stan to work with, so this parameterization of the model is typically preferred. Here is the Stan model:
// We save this as 8_schools_w_regression.stan
data {
int<lower=0> J; // number of schools
int N; // number of observations in the regression problem
real beta[J]; // estimated treatment effects from previous studies
real<lower=0> se[J]; // s.e. of those effect estimates
vector[N] y; // the outcomes for students in our fake study data
vector[N] treatment; // the treatment indicator in our fake study data
}
parameters {
real mu;
real<lower=0> tau;
real eta[J+1];
real<lower = 0> sigma;
real theta_hat;
}
transformed parameters {
real theta[J+1];
for (j in 1:(J+1)){
theta[j] = theta_hat + tau * eta[j];
}
}
model {
// priors
tau ~ cauchy(5, 2);
mu ~ normal(10, 2);
eta ~ normal(0, 1);
sigma ~ cauchy(3, 3);
theta_hat ~ normal(8, 5);
// parameter model for previous studies
for(j in 1:J) {
beta[j] ~ normal(theta[j], se[j]);
}
// our regression
y ~ normal(mu + theta[J+1]*treatment, sigma);
}
Now we estimate the model from R. Because of the geometry issues mentioned above, we use control = list(adapt_delta = 0.99)
to prompt Stan to take smaller step sizes, improving sampling performance at a cost of slower estimation time (this isn’t a problem here; it estimates in a couple of seconds).
eight_schools_plus_regression <- stan("8_schools_w_regression.stan",
data = list(beta = schools_dat$beta,
se = schools_dat$se,
J = 8,
y = y,
N = N,
treatment = treatment),
control = list(adapt_delta = 0.99))
Let’s comapare the estimates we get for our regression model to those we might get from the Bayesian model. A simple linear regression model gives us the following confidence intervals for the parameter estimates:
Our Bayesian model gives us more precise estimates for the treatment effect, with the 95% credibility region considerably smaller. This is because we have “borrowed”" information from the previous studies when estimating the treatment effect in the latest study. The estimates are also closer to the group-level mean.
print(eight_schools_plus_regression, pars = c("mu", "theta[9]", "theta_hat"), probs = c(0.025, 0.5, 0.975))
2.0.8 A note on reparameterizing
Hierarchical models are famous for inducing regions of high curvature in the typical set (see Betancourt 2017). Often, if we implement these directly we get many divergent transitions, in which we cannot trust the results. We often use a reparameterization to reshape the posterior into one that will not induce such curvature, as in the example above. These reparameterizations are typically of the following form:
Original random effects parameterization: \[ \theta_{k} \sim \mbox{Normal}(\theta, \sigma) \] New parameterization:
\[ \theta_{k} = \theta + \sigma z_{k} \mbox{ with } z_{k} \sim \mbox{Normal}(0, 1) \]
A similar idea works if you have multivariate parameters, for instance in a varying-intercepts varying-slopes model. This time, let \(\theta_{k}\) be a vector of parameters:
Original parameterization: \[ \theta_{k} \sim \mbox{Multi normal}(\theta, \Sigma) \] New parameterization: \[ \theta_{k} = \theta + \mbox{Chol}(\Sigma) z_{k} \mbox{ with } \mbox{vec}(z_{k}) \sim \mbox{Normal}(0, 1) \] Here, \(\mbox{Chol}(\Sigma)\) is the Cholesky factor of \(\Sigma\). Cholesky factors are a sort of square root operator for square invertable matrices.
2.0.9 Exercise 2: Panel data
In some recent research with Jeff Alstott (Media Lab, National Academy), we have been investigating whether the growth rates of technologies and the variation in their growth rates are related. One very simple model of the progress of technology \(y_{i,t}\) with continuous compounding growth rate \(g\) would be:
\[ \log(y_{i, t}) = a_{i} + g_{i}t + \epsilon_{i,t} \mbox{ with } \epsilon_{i,t} \sim \mbox{Normal}(0, \sigma_{i}) \] The research question is whether there is a strong correlation between \(\sigma_{i}\) and \(g_{i}\). Typically we will have, say, 10 observations of each technology (and for some, fewer), so we want to make sure that our inference appropriately accounts for the small-data nature. Because the data are small, estimates of \(a, g_{i}\) and \(\sigma\) will be noisy; if we can learn a good hyperprior for the model, we’ll be able to generate better predictions and inference.
A data generating process for such a correlated structure might be:
\[ \log(y_{i, t}) = a_{i} + g_{i}t + \epsilon_{i,t} \mbox{ with } \epsilon_{i,t} \sim \mbox{Normal}(0, \sigma_{i}) \] with
\[ (a_{i}, g_{i}, \log(\sigma_{i}))' \sim \mbox{Multi normal} \left(\mu, \mbox{diag}(\tau)\Omega\mbox{diag}(\tau)\right) \] where \(\mu\) is a vector of locations, \(\tau\) is a vector of scales, and \(\Omega\) is a correlation matrix.
Let’s simulate some data from this model:
library(dplyr); library(ggplot2)
set.seed(42)
T <- 10 # of observations per technology
J <- 20 # number of technologies
tau <- abs(rnorm(3))
Omega <- matrix(c(1, -.5, 0, -.5, 1, .5, 0, .5, 1), 3, 3)
Sigma <- diag(tau)%*% Omega %*% diag(tau)
mu <- c(1, 1, .3)
some_parameters <- as.data.frame(MASS::mvrnorm(J, mu, Sigma)) %>%
mutate(tech = 1:J,
sigma = exp(V3)) %>%
rename(a = V1, b = V2) %>%
select(-V3)
# A data grid
data_grid <- expand.grid(tech = 1:J, time = 1:T) %>%
left_join(some_parameters) %>%
mutate(technology_log_level = rnorm(n(), a + b*time, sigma)) %>%
arrange(tech, time)
# Have a look at the data
data_grid %>%
ggplot(aes(x = time, y = technology_log_level, group = tech)) +
geom_line()
Now, let’s code up the model, precisely as we propose the data generating process to be
// saved as models/simple_panel_reparam.stan
data {
int N; // number of observations in total
int J; // number of technologies
vector[N] time; // time
int tech[N]; // tech index
vector[N] y; // the log levels of the technology
}
parameters {
matrix[J, 3] z;
vector[3] theta_mu;
vector<lower = 0>[3] theta_tau;
corr_matrix[3] Omega;
}
transformed parameters {
matrix[J, 3] theta;
for(j in 1:J) {
theta[j] = (theta_mu + cholesky_decompose(quad_form_diag(Omega, theta_tau)) * z[j]')';
}
}
model {
theta_mu ~ normal(0, 1);
theta_tau ~ cauchy(0, 1);
Omega ~ lkj_corr(2);
to_vector(z) ~ normal(0, 1);
for(i in 1:N) {
y[i] ~ normal(theta[tech[i], 1] + theta[tech[i], 2]* time[i], exp(theta[tech[i], 3]));
}
}
Now let’s run it:
tech_mod <- stan_model("models/simple_panel_reparam.stan")
test_tech <- sampling(tech_mod, data = list(N = nrow(data_grid),
J = J, time = data_grid$time,
tech = data_grid$tech,
y = data_grid$technology_log_level), iter = 500)
# And let's look at our estimates
get_posterior_mean(test_tech, "theta")[,5] %>% matrix(J, 3, byrow = T)
print(test_tech, "theta_mu")
print(test_tech, "Omega")