How to understand ROC curve

During a layover on a Chrismas vacation to Alaska, I asked my friend who majors in statistic what an ROC curve is--a concept that had confused me for a long time. Although my friend gave me a detailed explanation, the only conclusion I remember is that the farther the curve is above from the y=x line, the better the ROC curve is. But how? Back home from vacation, I decided to figure it out. 

The x & y axis for ROC curve are False positive rate (FPR) and True positive rate (TPR) respectively. What are they? let me use a simply example from wikipedia to explain these concepts:

 

"imagine a study evaluating a test that screens people for a disease. Each  person taking the test either has or does not have the disease. The test outcome can be positive (classifying the person as having the disease) or negative (classifying the person as not having the disease). The test results for each subject may or may not match the subject's actual status. In that setting:

  • True positive: Sick people correctly identified as sick
  • False positive: Healthy people incorrectly identified as sick
  • True negative: Healthy people correctly identified as healthy
  • False negative: Sick people incorrectly identified as healthy

after getting the numbers of true positives, false positives, true negatives, and false negatives, the sensitivity and specificity for the test can be calculated. If it turns out the sensitivity is high then any person who has the diseases is likely to be classified as positive by the test. On the other hand, if the specificity is high, any person who does not have the disease is likely to be classified as negative by the test. " 

 They also give two straightforward pictures to illustrate concepts of sensitivity and specificity:


As for calculation of sensitivity, specificity, and FPR, we have:

sensitivity (TPR) = TP / (TP + FN)

specificity = TN / (TN + FP)

FPR = FP / (TN + FP) = 1 - specificity


Apparently, we hope TPR is as high as possible, and this is why the ROC curve should be farther above away y = x line.


 

 

Impossible triangle in life

In MRI, there is an "impossible triangle" formed by SNR, spatial resolution, and scan time. Improving any two inevitably comes at the expense of the third. High SNR and high resolution demand long scan times; short scans with high resolution suffer from low SNR; and achieving both high SNR and short scan times requires sacrificing spatial resolution.

I recently realized that life seems to follow a similar "impossible triangle" defined by money, time, and energy. In youth, we possess time and energy but lack money. In middle age, we gain money and energy but lose time. In old age, we may finally have time and money, yet no longer have the energy to fully enjoy them.

 


 

Good to know

Greg Mankiw's blog is a website I visit often. I just realized that he’s the author of the two well-known economics textbooks Principles of Macroeconomics and Principles of Microeconomics. I had only known these books and their author by their Chinese names — which is a bit embarrassing.

[Visual Studio] .dll & .lib

 DLL = Dynamic Link Library

 it contains compiled machine code for functions, classes, etc., but not in a form the linker can use directly.

 DLLs are loaded at runtime (when your program starts, or later if you load them manually).

 if the DLL is missing at runtime, you get errors like

The program can't start because *.dll is missing...

There are two types of .lib files in Visual Studio:

 (a) Static Library (.lib)

  • Contains all compiled code directly
  • Gets copied into your .exe during linking
  • No DLL is needed at runtime--the code is inside your executable

 (b) Import Library (.lib)

  • This is the one used with DLLs
  • It does not contain the code itself -- it only contains symbol information (function names, addresses) so the linker knows:
    • Which functions your code will call
    • That they will be found inside a specific DLL at runtime.
  • At link time, you give the linker the .lib (so it knows what you're calling) and at runtime you place .dll next to your .exe (so it can actually run).

Think of the .lib as the map that tells your program "The hammer is in that toolbox over there", and the .dll as the toolbox itself. 

 

 

env not found in kernel picker on vs code

If you are testing the *.ipynb files using vs code, after you create a new env with conda:

$ conda create -n <your_name> 

you will notice that you can NOT find env name you just created. Installing ipykernel will help you address this issue

$ conda install ipykernel 

Why don't Students like School

Until recently, I didn't know that there is a well-know book titled Why don't students like school?, written by Daniel T. Willingham, a professor at our Univeristy — the University of Virginia. The book offers some insightful ideas about how we think:

  • The mind is not designed for thinking—it's designed to save you from thinking: In other words, thinking is effortful, and students will avoid it unless they are motivated and the conditions are right.
  • People are naturally curious—but only if the problem is the right level of difficulty: If it's too hard, they give up; if it's too easy, they get bored.
  • Memory is the residue of thought: We remember what we think about. So, lessons should focus students' thinking on the right things. 
  • Factual knowledge is essential for critical thinking: The more you know, the easier it is to understand, learn new things, and think critically.
  • Students learn better when lessons are meaningful and connected to prior knowledge.
  • Teaching should build on stories, emotions, and visuals—because those are what the brain remembers best.
Here is a brief summary of this article. 

 

Present Perfect Tense & Simple Past Tense

  1.  Present Perfect Tense (have/has + past participle) 
  • Form:
    • I have eaten, She has gone, We have finished.
  • Use:
    • Refers to past actions that are connected to the present. Often used when:
      • The exact time is not mentioned
      • The result still matters now
      • The action has happened at some point in the past (unspecified time)
  • Examples
    • I have eaten breakfast. (You may still be full now)
    • She has visited Japan. (In her life, at some time -- we don't say when)
    • We've just finished the project. (The result affects the present)
 

     2. Simple Past Tense (verb + -ed or past form)

  • Form:
    • I ate, She went, We finished
  • Use:
    • Refer to completed actions that in the past usually with a specific time (even if it's implied)
  • Examples:
    • I ate breakfast at 8 a.m. (Specific time in the past)
    • She visited Japan in 2020.
    • We finished the project last week

Kahil Gibran: On Children

And a woman who held a babe against her bosom said, Speak to us of Children.

And he said:

Your children are not your children.

They are the sons and daughters of Life's longing for itself.

They come through you but not from you.

And though they are with you yet they belong not to you.

You might give them your love but not your thoughts,

For they have their own thoughts.

You may house their bodies but not their souls,

For their souls dwell in the house of tomorrow, which you cannot visit, not even in your dreams.

You may strive to be like them, but seek not to make them like you.

For life goes not backward nor tarries with yesterday.

You are the bows from which your children as living arrows are sent forth.

The archer sees the mark upon the path of the infinite, and He bends you    with his might that His arrows may go swift and far. 

Let your bending in the archer's hand be for gladness;

For even as He loves the arrow that flies, so He loves also the bow that is stable.

Taste

[statement] this article is from Andrew Abbott's book: Methods of Discovery: Heuristics for the Social Sciences
 
---

Conventions and the problem of knowing them bring us to the matter of taste. Judging one's ideas becomes much easier when one begins  to acquire scholarly taste. By taste, I mean a general, intuitive sense of whether an idea is likely to be a good one or not. It is of course important not to become a slave of ones' taste, to try new things as one tries new foods. But developing a sense of taste makes things a lot easier.

The foundation of good taste -- like the foundation of good heuristic -- is broad reading. It is not necessary that all the reading be of good material, only that it be broad and that it always involve judgment and reflection. A musical metaphor is again useful. A good pianist always practices not only technique and repertoire but also sight-reading for pianists. A pianist practicing sight-reading grabs a random piece of music and reads it through, playing steadily on in spite of  mistakes and omissions. So, too, should you just pick up pieces of social science or sociology or whatever and just read through them, whether you know the details of the methods, see the complexities of the argument, or even like the style of analysis. The obvious way to do this is to pick up recent issues of journals and quickly read straight through them.

You learn many things from such broad reading. You learn the zones of research in the discipline. You learn the conventions of each zone, and you figure out which you like and which you don't like. You learn what interests you and what does not. Of course, you should not let your interests dictate your reactions, just as you should disregard, when you are "sight-reading," conventions with which you disagree. When you find you don't like a paper's methodology and you think its concepts don't make sense, force yourself to go on and ask what there is that you can get out of it -- perhaps some facts, a hypothesis, even (in the worst case) some references. In the best disciplinary journals, every article will have something to teach you, even those articles that lie completely outside your own preferences.

 This is also a useful rule for seminars and lectures, which are another useful place to develop your taste. There is no point in sitting through a lecture or talk whose methods you hate, self-righteously telling yourself about the "positivist morons" or the "postmodern bullshit" or whatever. All that does is reinforce your prejudices and teach you nothing. Judge a talk or a paper with respect to what it is itself trying to do. This is hard, but by working at it, you will gain a much surer sense of both the strengths and weaknesses of your own preferences. You will become able to gather useful ideas, theories, facts, and methodological tricks from material that used to tell you nothing.

You will, of course, run into plenty of bad stuff: bad books, bad papers, bad talks. The symptoms are usually pretty clear: pontification, confusion, aimlessness, overreliance on authorities. Other  signs are excessive attention to methods rather than substance and long discussions of the speaker's or writer's positions on various important debates. But even bad material can t each you things. Most important, it can teach you how to set standards for an article or talk on its own terms. What was the writer trying to accomplish? For the truly terrible, what should the write have been trying to accomplish? This last is the question that enables you to judge material on its own grounds, by imagining the task it should have set itself.

Of  course, it is also important self-consciously to read good work. Oddly enough, good work will not teach you as much as will bad. Great social science  tends to look self-evident after the fact, and when it's well written, you may not be able to see what the insight was that instituted a new paradigm. What you take away from good work is more its sense of excitement and clarity, its feeling of ease and fluidity. Not that these are very imitable. But they set an ideal.

How does one find such good work? At the start, you ask people you know -- faculty members, friends, fellow students. You also look at influential material, although -- again oddly -- there is plenty of influential material that is badly argued and opaque. Soon your taste will establish itself, and you can rely more on your own judgment. There is no substitute for practice and, in particular, for "sight-reading." You just need to learn to read and make judgments, always working around your own prejudices to separate bad work from work you simply don't like.

Developing this taste about others' ideas is a crucial step toward judging your own. Even given all the hints scattered throughout this chapter, judging your own ideas is the hardest task of all. The only way to become skilled at it is to acquire general taste and then carefully and painfully turn that taste on your own thinking. The skill of learning to find good and bad things in the work of others can be the best help in finding the good and bad things in your own work.

CLI is more efficient now

I opened MATLAB as usual and found that my workspace was missing for no apparent reason. I tried to recover it by searching online and planned to follow step-by-step instructions with screen shots. Suddenly, I came across an answer suggesting I simply type workspace, and it  worked. A talented Chinese software developer once said the same idea on social media platform X, formerly known as Twitter.

htthttps://x.com/cloudwu/status/1914176415962116149ps://x.com/cloudwu/status/1914176415962116149
https://x.com/cloudwu/status/1914176415962116149

The Cult of Genius

[Statement] This article was written by Julianne Dalcanton for Discover Magazine. I really enjoy reading it, but the surrounding ads were incredibly distracting and annoying. So I decided to copy it onto my blog for a smoother reading experience. Please note that red-labeled words indicate typos found in the original article. If this post violates any copyright, please contact me at bmekangyan@gmail.com and I'll take it down immediately.

------

While some physicists are known for their hearty support of atheism, even they can have some personal dieties. High in the physicist's pantheon sits Richard Feynman, due not only to his obvious smarts and good work, but also to an outsized personality chronicled ['chonicled'] in a wealth of popular writings (and even a movie!). I've nothing personal against Feynman in particular, but about the hero worship he represents. During high school or college, many aspiring physicists latch onto Feynman or Einstein or Hawking as representing all they hope to become. The problem is, the vast majority of us are just not that smart. Oh sure, we've plenty clever, and are whizzes at figuring out the tip when the check comes due, but we're not Feynman-Einstein-Hawking smart. We go through a phase where we hope that we are, and then reality set in, and we either (1) deal, (2) spend the rest of our career trying to hide the fact that we're not, or (3) drop out. It's always bugged the crap out of me that physicists' worship of genius conveys the simultaneous message that if you're not F-E-H smart, then what good are you? In physics recommendation land, there is no more damning praise than saying someone is a "hard worker".

Well, screw that. Yes, you have to be clever, but if you have good taste in problems, an ability to forge intellectual connections, an eye for untapped opportunities, drive, and yes, a willingness to work hard, you can have major impacts on the field. While my guess is that this is broadly understood to be true by those of us clever-but-not-F-E-H-smart folks who've survived the weeding of graduate school, postdoctoral positions, and assistant professorhood, we do a lousy job of communicating this fact to our students. I've always suspected that we lose talent from the field because people opt for Door #3 (drop out) when the going gets rough. (I have no idea if other fields have this same problem—my guess is that physicists are particularly prone to it, since we are trained early on to think that physicists are simply smarter than chemists or biologists. Those other fields are for the hard workers. We don't put mathematicians on this scale, because we secretly believe they're smarter than us. Note to the biologist lynch mob: tongue ['tounge'] is in cheek.)

Anyways, I've been thinking about this again in light of Po Bronson's excellent article in New York Magazine about Carol Dweck's research (which I read via Nordette in Blogher is coming out in a popular book Mindset: The New Psychology of Success). The  article is focused on how to effectively handle praise for smart kids. The upshot (verified by a number of clever experiments), is that when you praise a kid for being smart in general, rather than for specific accomplishments or efforts, you risk paralyzing the kid with a fear of not looking smart, to the point where they will tend to shun challenges.

In follow-up interviews, Dweck discovered that those who think that innate intelligence is the key to success begin to discount the importance of effort. I am smart, the kids' reasoning goes; I don't need to put out effort. Expending effort becomes stigmatized, it's public proof that you can't cut it on your natural gifts.

Repeating her experiments, Dweck found this effect of praise on performance held true for students of every socioeconomic class. It hit both boys and girls, the very brightest girls especially (they collapsed the most following failure).

While Dweck is working primarily with preK-12 students, everything covered in the article rings true for what I've seen at the higher levels (both for myself, my colleagues, and students). Those of us who are fortunate enough to sail through high school often crumple when the stuff we've allegedly good at finally becomes hard. Whether you "make it" as a physicist after that has a lot to do with how you respond at that moment. Do you take it as a sign that you're not cut out for the game? Do you feel like a failure, and stop enjoying physics as a whole? Do you buck up and forge ahead? (Like a neutrino, you'll probably wind up oscillating among the three mixed states for a while, before collapsing into one of them.)

I was most struck in Bronson's article by a description of an experiment by Lisa Blackwell and Dweck on the impact on performance of how one perceives intelligence. In a science magnet school with low achieving ['acheiving'] students, Blackwell studied 700 students, all of whom were taught a multi-session unit on study skills. One half of the group, however, also received a "special module on how intelligence is not innate ['inate']":

The teachers, who hadn't known which students had been assigned to which workshop, could pick out the students who had been taught that intelligence can be developed. They improved their study habits and grades. In a single semester, Blackwell reversed the students' longtime trend of decreasing math grades.

The only difference between the control group and the rest group were two lessons, a total of 50 minutes spent teaching not math but a single idea: that the brain is a muscle. Giving it a harder workout makes you smarter. That alone improved their math scores.

These studies have lots of implications for higher ed in the sciences. Physics, with its strong cult of genius, is probably the canary in the coal mine.

Social Media are in decline nowadays

 "Overall, consistency, user control, and actual UX innovation are in decline. Everything is converging on TikTok—which is basically TV with infinite channels. You don't control anything except the channel switch. It's like Carcinisation, a form of convergent evolution where unrelated crustaceans all evolve into something vaguely crab-shaped."

by Rakhim's blog, But what if I really want a faster horse?

 

Using SSH with X11 Forwarding for Remote Image Display

I personally really enjoy working with the command line and using SSH. It's fast, powerful, and great for development. However, since our research involves medical images, being able to display images remotely is an important (and frequent) task.

When i first tried setting this up on my Windows PC, it didn't work out of the box. After some troubleshooting under the help of ChatGPT, i figured it out — so here are a few tips that might help you too!

1. SSH with X11 Forwarding

When connecting to your remote server, use the -X (or -Y) flag to enable X11 forwarding:

ssh -X user@remote-host

check that the DISPLAY variable is set after login:

echo $DISPLAY 

You should see something like localhost:10.0

2. Install X11 libraries on the remote machine

On the remote host, make sure the necessary X11 packages are installed:

sudo apt uodate

sudo apt install x11-apps python3-tk

To test if it's working, run:

xeyes

if the eyeballs show up, X11 is working! 

3. Local machine must have X11 server (macOS or Windows)

macOS

Install XQuartz 

After install, run XQuartz and reconnect using:

ssh -Y/-X user@remote-host

Windows 

If you're on a Windows system, you'll need to install an X11 server like:

Here's how you set up VcXsrv:

  • Download and install VcXsrv
  • Run "XLaunch
  • Select:
    • Multiple windows
    • Start with "Start no client"
    • Enable "Disable access control" (or configure access if needed)
    • Finish and leave it running in the background

Now, to connect:

  • Use MobaXterm or PuTTY with X11 forwarding enabled
  • Important: Windows CMD and PowerShell donot support X11 forwarding directly. You'll need to use WSL or an SSH client that supports X11.

How T1 changes with magnetic field stength?

[Reference source]

Conclusion: T1 increases and T2  doesn't change very much as B0 increases.

Benefits of long T1 

  • ASL: 

 

 

What is CPMG condition?


The CPMG (Carr-Purcell-Meiboom-Gill) condition is frequently mentioned in spin-echo-related research papers, yet it's rarely explained in detail.

First off,  Carr, Purcell, Meiboom, and Gill are the researchers who contributed to this technique. According to MRI Questions:

In the early SE (spin echo) experiments by Hahn (1850) and Carr and Purcell (1954) , RF pulses were all applied along the same axis (usually x-direction). In practice, this method resulted in measured T2 values that were too short because of (1) cumulative phase errors from repetitive imperfect 180 pulses, and (2) B1 inhomogeneity effects that spread the magnetization out in a plane containing B1 and B0. In 1958 Meiboom and Gill proposed that such pulse-related errors could be reduced if the 180 pulses in a SE train were phase shifted 90 with respect to the initial 90 pulse. In other words, if the 90 pulse were applied along the x-axis, the 180 pulses would be applied alternately along the +-y-axes. This technique, subsequently known by the acronym CPMG...

 

This raises an important question: why does applying both the 90 and 180 RF pulses along the same axis lead to underestimated T2 values?

 


 

The above figure which came from the original paper by Meiboom and Gill, described the behavior of the nuclear polarization without 90 shift of the first 90 pulse. Therefore, we can conclude that:

  • the polarization vector at the time of the echos is alternatively in the +y and -y directions.
  • If the 180 pulses deviate from the true 180 amplitude, the corresponding error is cumulative, and successive pulses will rotate the polarization vectors more and more out of the xy plane.  

The modification: