text:
Home HIV
Articles Jan 17, 2020
Articles Dec 2, 2019
Stigmatisation of people livingwith HIV fuelling spread ofvirus
Private sector pledges to supportFG in HIV/AIDS treatment
Govt Launches 'U=U' CampaignAgainst HIV/Aids
HIV Dec 5, 2016
HIV – Ex-Super Eagles StarsPlay Against Nollywood Starsto Raise Awareness
About 500 Nigerians Die ofHIV/Aids Daily – Naca
by admin - Jan 17, 2020
Dental implants are artificial structures that a dental surgeon inserts into a person's jawbone. A person may need an implant if they have lost one or more teeth.
Keep reading to learn about the types of implants and associated risks. We also describe what to expect from dental implant surgery and how much the procedure may cost.
A dental implant is a structure that replaces a missing tooth. With screw-like devices, the surgeon inserts an implant into the jawbone, and it acts as an anchor for an artificial tooth, called a crown.
A device called an abutment connects the artificial tooth to the dental implant.
The crown is custom-made to fit the person's mouth and match the color of their teeth. Crowns look, feel, and function like natural teeth.
Implants have several advantages over dentures, which are removable artificial teeth. Implants:
are more natural and comfortable
have a higher success rate
improve chewing function
lead to a lower risk of cavities developing in nearby teeth
lead to better maintenance of bone at the site of the lost tooth
cause decreased sensitivity in nearby teeth
do not need to be taken out and cleaned every night
However, dental implants are not suitable for everyone. The implanting devices must bond with the jawbone, so a person's bones must be healthy before they can undergo implant surgery.
There are two types of dental implant: endosteal and subperiosteal.
Endosteal implants are the most common type. A surgeon embeds them in the jawbone, and each can hold one or more artificial teeth.
A surgeon affixes a subperiosteal implant on top of the jawbone. Dental surgeons choose this option for people who do not have much height to their jawbone.
According to the American Academy of Implant Dentistry, around 3 million people in the United States have dental implants, and this number increases by about 500,000 every year.
Dental implant surgery is safe when a qualified and experienced surgeon or dentist performs it. It is also the only dental restoration option that maintains the health of the person's jawbone and stimulates its growth.
Some people are not eligible for dental implant surgery. It is not safe for dental surgeons to operate on people with:
acute illness
uncontrollable metabolic disease
bone or soft tissue disease or infection
If these issues are resolved, a person can have the surgery.
In some cases, dental surgeons refrain from operating on people with:
heavy smoking habits
parafunctional habits, such as tooth grinding or clenching
behavioral or psychiatric disorders
If people with any of the above undergo dental implant surgery, there is a higher risk of the implant failing.
Dental surgeons may also choose not to operate on people undergoing the following treatments, due to an increased risk of implant complications:
bisphosphonate drug treatment for bone loss diseases
radiation therapy of the head or neck
Potential complications of implant surgery
People who undergo this procedure may experience complications during or afterward. The issues may include:
nerve damage, resulting in altered sensation in the surgical area
an opening of the incision following surgery
movement of the implant
exposure of the implant above the gumline
infection of the implant
People who experience movement or exposure of the implant may need to undergo additional procedures to improve the health of the bone and gums or remove or replace the implant.
The following are some signs and symptoms that an implant placement has been unsuccessful:
the implant is excessively mobile
pus or other secretions come from the site
pain when tapping the implant
rapid, progressive bone loss
Each person is likely to have a different experience of dental implant surgery. Factors that may influence this include:
the number of teeth requiring replacement
the location of the implants within the jaw
the quality and quantity of bone at the implant site
the person's underlying oral and systemic health
Depending on these factors, additional procedures may be necessary. These can include:
Placing an implant in the upper jawbone is usually difficult because of the location of the sinuses.
The surgeon may need to perform a sinus augmentation — a procedure to lift the floor of the sinuses to allow more bone to develop so that the implantation can be successful.
Some people have a jawbone abnormality that prevents enough bone for an implant from developing. In such cases, a surgeon may need to perform a ridge modification.
This involves lifting the gum to expose the area of deformed bone. The surgeon will then use a bone or bone substitute to repair and build up the area. This improves the quality of the jawbone in preparation for dental implant surgery.
After a person has undergone dental implant surgery, they must continue to brush and floss their teeth regularly. Artificial teeth require the same care and maintenance as regular teeth.
The surgeon or dentist will also schedule follow-up visits to monitor the implants and make sure that the teeth and gums are healthy. It is important to return to the dentist every 6 months for professional cleanings.
The cost of dental implant surgery varies, and the following factors can influence it:
the number and types of implants required
whether there is a need for any additional procedures to prepare the mouth for surgery
A dentist or another oral health professional can estimate the cost of dental implant surgery during an initial examination.
Some dental insurance policies cover a larger portion of the cost.
Other tooth replacement options, such as bridges, may be less expensive. However, bridges are harder to keep clean and often require replacement and repair, increasing the overall cost. Dental implants may provide longer-term benefits if a person takes care of them well.
Dental implants are fixtures in the bone that replace missing teeth. Implants have a high success rate and can provide long-term benefits.
Some people need additional procedures to prepare their mouth for dental implants. These will add to the overall cost. The number and type of implants required can also raise the cost.
Anyone considering dental implant surgery should ask their dentist whether it is right for them.
Stigmatisation of people living with HIV fuelling spread of virus
As the world marks the 2019 World Aids Day today, stigmatisation and discrimination against Persons Living With HIV/AIDS (PLWHAs) remain the twin factors frustrating a successful fight against the dreaded scourge.
Not only have they prevented people from coming forward to know their status and consequently commence early treatment where result turns out positive, these factors also pose a threat to meeting the 2030 global target to end AIDS.
For PLWHAs, the constant psychological trauma they contend with at treatment centres and in communities where they live further makes life difficult. In fact, the reality of living with a life-threatening ailment finds expression daily in the discriminating and stigmatising behaviours directed at them within their environment.
For instance, "You this dead woman, a living corpse, leave my house!" was how Funmi Okafor, a mother of four children was welcomed as she returned home from the hospital after receiving the news that she tested positive to Human Immunodeficiency Virus (HIV), after weeks of constant sickness that defied treatment.
Okafor, who was squatting with a friend, (alongside her kids) after the death of her husband, met her belongings outside, drenched in rainwater, while her friend stood by the door post yelling at her to move away with her children.
With nowhere else to put up, she was forced to move into an incomplete building as her new home.
The mother of four's journey to this sad realisation started when she noticed rashes on her body, while she was constantly ill and began to lose weight in the process.
With the constant illness, which she thought was malaria fever (as many people would think first), she, however, decided to visit a nurse, whom she told about her constant "malaria fever."
The nurse took her blood sample to the laboratory to carry out malaria, typhoid, and HIV tests. And on confirming the cause of Okafor's ailment, the nurse, due to lack of knowledge about patient's right to confidentiality, refused to inform Okafor that she tested positive to HIV, but rather spread the news around the community where she lived in Edo state.
Determined to know the ailment that has caused her to emaciate, with rashes all over her body, Okafor visited a general hospital, where after the test she was pronounced HIV positive.
"I went to a nurse and told her that I had malaria fever. She took my blood sample to the laboratory. But instead of her disclosing my condition to me, she told my friend, who spread the rumour around. I still was not aware of my status because she did not disclose it to me. It was only after I went to the general hospital that I knew my condition.
"The day I was supposed to be placed on drugs, it rained heavily, and by the time I returned to where I squatted with my children, my host had thrown out all my belongings. After yelling at me and calling me names, I packed what was left of my property and moved," she recalled.
Before long, Okafor became the butt of jokes in the community where she lived in Edo State, and others avoided contact or any relationship with her. Since she could not stand being ostracised like that, she relocated to Lagos with her children.
She lamented: "It is not easy to cope with life when you are HIV positive. My father and husband are late, while my mother and siblings are in the village. But I was almost alone in the world before I relocated to Lagos because everyone started deserting me," she said.
CHINWE IKE was pregnant when she discovered that she was HIV positive. She felt like taking her life and for several nights thoughts of suicide assailed her, especially because she did not know what the virus was all about, as people kept saying different things about it.
At the early stage of her pregnancy in 2006, she was on admission to a hospital for one week before she was transferred to another hospital for further treatment.
However, when she went into labour, her HIV status was confirmed in a private hospital, and the doctor in charge of the case requested that she invited a trusted relative over, who would thereafter break the news to her in a calm manner, and get her to accept her condition.
"I decided to invite my friend, who is a nurse instead of a relative. Unfortunately, after she heard of my condition, she went about scandalising me to the extent that my landlady came to me one day and asked me to leave her house. It was afterward that I discovered that it was that my nurse friend that fed everyone with details of my HIV status. Since my landlady insisted that I should leave her apartment, I did," she said.
Ike added that it was after she left the compound before she started understanding many things about the disease, her rights as a Person Living With HIV (PLWHA). "Just because I did not know anything I had to leave the compound because they were threatening to kill me. Since then I have been living with that stigma and picking up the pieces of my life.
"It is 13 years now and I am still alive. My friend told me then that I had dug my grave, but after some years, I went back to my former neighbourhood for them to see that I am still alive, and when they saw me, most of them were surprised. However, because of the scandal, I lost my job as a secretary/cashier at a company located at the Alaba International Market, Lagos."
Since 2001 that Chika Nnoroka discovered that she and her 18-month-old son were HIV positive, she has faced extreme stigmatisation and discrimination, not only in her community but also at medical facilities.
She narrated, "The stigmatisation and discrimination got so intense that I did not believe that I and my son would survive. People were keeping away from us, even the doctors and nurses were all stigmatising people living with HIV to the extent that most of us were finding it difficult to go to the facility to access treatment."
Nnoroka said women were more vulnerable to HIV/AIDS stigmatisation, as many that have lost their husbands were being denied by their family members and friends. Their rights and privileges are also denied.
"By the time I got information from the doctor that there was a treatment to suppress the virus, I was a little bit relieved, but I was afraid for my little son, who just came into this world. I was not bothered about myself," she said.
Chika's son, who is now a 20-year-old, is waxing strong with the help of the drugs.
Misconceptions On Mode Of Transmission
Okafor, who has lived with the virus for 19 years said, "most people think that all women living with HIV are prostitutes. My husband was the one that deflowered me; you can contract HIV/AIDS from anywhere.
"I want people to change the narrative that ladies living with HIV/AIDS are wayward, I believe that is why people do not want to come out to check their status or speak up that they have the virus."
Okafor who narrated how she contracted the virus said, "It was late but the symptoms in my husband's body showed that he had HIV and he lied to me that it was severe cough. His close friend was the one who disclosed to me that my husband was HIV positive and that his family is keeping it away from me. He said I should go and check myself if I also have the virus.
"I did my test and found out that I was positive. My husband was never a womaniser; I suspect he contracted HIV when he was stabbed him in the chest. He had internal bleeding in his lungs and the hospital asked us to get nine pints of blood, this was during the early 1980s. I strongly believe that it was then that he contracted the disease."
Ike on her part said: "I am somebody that does not flirt around, I contracted HIV through my husband. It was when I got married to him that I discovered that I had the virus. Initially, I could not believe that I was down with that kind of health problem."
According to the World Health Organisation (WHO), HIV can be transmitted through close contact with specific body fluids of persons living with the virus. Apart from fluids such as blood, semen, and breast milk; unprotected sex, body piercing equipment, or sharp objects are also vehicles of transmission. Transmission can also be done through mother-to-baby during pregnancy and through contaminated blood transfusion.
'Cost' Of Drugs Limiting Access To Treatment
With many of the people living with the virus jobless, and without hope of employment, affording the drugs for treatment and other medical procedures becomes difficult.
Ike said: "These drugs that we are taking are to sustain our lives and we have to eat well before taking them. What I am emphasising on is that the government should help us because right now, we are paying for drugs, and not everyone can afford it. We pay N2, 000 for consultation; N1, 000 for drugs and almost N3, 000 for laboratory. Not everybody that is HIV positive can afford it, so we are begging the government to help people living with HIV, by making drugs and treatment procedures free. It is laughable when we are told that the drugs are free of charge, and when we get to the hospital we are told to pay for the procedures that I have mentioned.
Findings by The Guardian reveal that because of rising stigmatisation, many people living with HIV/AIDS are staying away from hospitals, while those who suspect their status do not make themselves available for examination. Because of all these, and the inability of many to access treatment early, more people are getting infected and dying from the virus.
This is also why some cases have remained undetected, a development that poses more danger to the country, as those who are unaware of their status could infect others, thereby increasing the spread of the virus.
Ike, who revealed an earlier encounter, which nearly ended her life said: "When I went to a laboratory to do another test to confirm my status, the lab scientists told me that people with the virus can neither get married nor have children. With that impression, I refused to go to the hospital or any other institution for treatment. I concluded that I would commit suicide at home one day."
Ike who lost her husband to the virus continued: "Because of this stigmatisation people find it difficult to disclose their HIV status because once they do, the news spreads so fast and then sooner than later they are shut out of their families and the society. Where I reside now, I have kept my HIV status a big secret.
"Some people do not even believe that there is something like a discordant couple, where either of the partners is negative, while the other is positive. The reality is that when two people are dating and then one discloses his or her HIV status to the other, the relationship breaks up immediately because they do not believe that those who are positive can have children who are HIV negative," she explained.
Ike added that her refusal to take treatment cost her two-month-old her life after she developed cough and died. This made her summon courage and head to head to the hospital for treatment.
Private sector pledges to support FG in HIV/AIDS treatment
Nigerian Business Coalition Against AIDS (NiBUCAA) has promised to support the Federal Government in providing Antiretroviral (ARV) therapy to boost treatment and care for people living with the Human Immunodeficiency Virus/Acquired Immune Deficiency Syndrome (HIV/AIDS).
The executive secretary, Gbenga Alabi, said the move was in line with the 'Communities Make the Difference' theme of the 2019 World AIDS Day.
World AIDS Day, marked on December 1 since 1988, is an international day dedicated to raising awareness on the AIDS pandemic caused by the spread of HIV infection and mourning those who have died of the disease.
According to him, ARVs, which suppress the HIV, stop the progression of the disease and prevent onward transmission, are very expensive, with the United States (U.S.) government supporting Nigeria in its provision.
Once the U.S. pulls out of the supply of the drugs, Nigeria will suffer great loss, he added.
"In fact, more than 70 per cent of ARVs in Nigeria are provided by U.S. government and there is need for us, at this point, to try to own it and sustain it.
"So, ownership and sustainability is the sole responsibility of the government. But government cannot do it alone; that is why the private sector has to come on board to complement government's effort," he said.
He said the private sector was also assisting in the provision of testing kits to health facilities, as well as helping carriers to manage the virus.
"As we commemorate the 2019 World AIDS Day, NiBUCAA is making a call for increased access to HIV testing and increased uptake of HIV testing.
"Around the world, 37 million people are living with HIV, yet a quarter does not know that they have the virus.
"Knowing your HIV status has many advantages. It is an essential entry point to HIV treatment, prevention, care and support services. People who test positive are linked immediately to ARV therapy. There has been a good progress on HIV testing and treatment driven by a strong growing commitment to achieve 90-90-90 targets by 2020," he said.
Alabi added that as part of global efforts to end AIDS by 2030, the coalition would provide free HIV testing services to 5,000 people across various 20 councils in Lagos State for eight consecutive days from Monday, November 25.
Govt Launches 'U=U' Campaign Against HIV/Aids
The federal government has launched the Undetectable equals Untransmittable (U=U) campaign to promote the benefit of treatment to people living with HIV/AIDS and encourage them to access treatment.
Launching the campaign in commemoration of the 2019 World AIDS Day (WAD) with theme, 'Communities Make the Difference' on behalf of government, through the Federal Ministry of Health (FMoH) and the National Agency for the Control of AIDS (NACA) in conjunction with the President's Emergency Plan for AIDS Relief (PEPFAR), Senate President Ahmed Lawan said Nigeria was launching an important and strategic campaign to help the country achieve zero new HIV infections and reduce stigma for Nigerians living with HIV.
He said, Nigeria is reaffirming its commitment through all the relevant communities to make the difference in the National HIV response to attain the 90-90-90 goal by the end of 2020.
The Director General, NACA, Dr Aliyu Gambo said, the theme of this year's WAD acknowledged the essential role communities play in the global HIV response.
HIV – Ex-Super Eagles Stars Play Against Nollywood Stars to Raise Awareness
by - Dec 5, 2016
In a bid to make this year's World AIDS Day highly impactful, the Nigeria Red Ribbon Coalition, a strategic public-private sector alliance, organised a novelty football match yesterday in Lagos to raise awareness about HIV/AIDS and also provide free HIV Testing and Counselling services.
The celebrity football match featured ex-international football stars who have carved a niche for themselves in the soccer sporting world as well as notable celebrities in the Nigerian music and film industry.
Leading the Ex-international stars were Emmanuel Babayaro (health Ambassador and Ex-Super Eagles Goalkeeper), Ifeanyi Udeze, Victor Agali, Emmanuel Okocha, Abdul Isah and several others. Representing the movie and music industry were stars like Belinda Effah (actress and presenter), John Njamah (actor/movie producer), ID Cabassa (popular music producer whose real name is Olumide Ogunade), Sound Sultan (a Nigerian rapper, singer-songwriter, actor, comedian and recording artist, born Olanrewaju Fasasi), and a host of other celebrities who took time out of their busy schedules to join hands in pushing back the scourge of our common adversary – HIV.
The coalition convened by Coca-Cola , Nigeria comprises Youth Empowerment Foundation (YEF), Youth Empowerment and Development Initiative (YEDI), Society for Family Health (SFH).
Declaring the match open, the convener and Community Affairs Manager, Coca-Cola Nigeria, Emeka Mba, reiterated the company's resolve to support grassroots innovative approaches aimed at improving lives nationwide. He noted that the Coalition which started last year, was building on the successes made at the inaugural edition in 2015 by mobilizing and sensitizing people to know their status with the provision of free HIV testing services in a friendly environment, tackling issues of stigmatization, discrimination and fear of getting tested, promoting social inclusion and adequate care for People Living with HIV/AIDS (PLWHA) and stimulating a larger stakeholder involvement.
Mba added that no individual, government, or organisation can single-handedly make meaningful progress in the fight against HIV/AID, hence the need for a coalition.
In her remarks, the Executive Director, Youth Empowerment and Development Initiative (YEDI), Anu Ishola underscored the coalition's strategy of leveraging each party's organisational strength and corporate core competences that has brought the pan-Nigeria alliance thus far.
"We decided to have a strategic alliance that boasts of credible NGOs like Society for Family Health, Youth Empowerment Foundation (YEF), YEDI and other private sector partners like Ford Foundation, Federal Palace Hotel, Owu SportsWear, etc. Coupled with celebrity advocacy – with a star-studded Novelty match on the side, we have been able to reach out to a large spectrum of people who have come out not just to watch football, but also to voluntarily get tested and counselled for HIV."
She expressed gratitude to global beverage giant Coca-Cola – the chief funder of the initiative and MAC AIDS as well as other partners who are contributing immensely to the fight against HIV/AIDS.
On the impact of a novelty match in combating HIV, the leader of the ex-International who is also a health Ambassador, Emmanuel Hyacinth Babayaro, older brother of former Chelsea and Newcastle United player Celestine Babayaro said:"We are leveraging celebrity advocacy and role modelling to mobilize people because behind every celebrity or role model, there are a thousand and one people who would like to emulate them.
So we have all of them here today for free because they believe in this cause and they want to contribute their quota. Young people came out here today to be tested and get accurate information about HIV/AIDS. Our target this year is to provide free HIV Counselling and Testing to 18,000 persons across 11 states in Nigeria including Akwa Ibom, Anambra, Edo, Enugu, FCT Abuja, Gombe, Imo, Kaduna, Kano, Lagos, and Oyo with a combination of activities including this novelty match. I'm happy to be a part of this."
In her views, Iwalola Akin-Jimoh the Executive Director of YEF, the novelty match and other activities were important as they serve as ways of reminding the Government, private sector organisations and the general public that HIV has not gone away and that collectively, there is the need to increase awareness, fight prejudice and stigmatization, improve awareness/sensitization channels and develop appropriate funded programmes to maintain the drive towards eradicating the scourge.
The fun-filled novelty match which drew a huge crowd within the Lagos Island environs, including Mr. Ibrahim Umoru, Executive Director, Good Health Educators Initiative and former coordinator, Lagos State Chapter of the Network of People Living with HIV/AIDS in Nigeria, ended 5-3, in favour of ex-internationals who played against celebrities and corporate Nigeria. There was also a celebrity placard display with various messages to raise awareness about HIV as well as o one-minute in respect of those who have died as a result of the dreaded virus.
About 500 Nigerians Die of HIV/Aids Daily – Naca
At least 500 Nigerians die of HIV/AIDs daily, with an average new infection of 600 people every day, says Sani Aliyu, Director General, National Agency for the Control of AIDs, NACA.
Mr. Aliyu gave the figure during an interview with the Nigerian Television Authority, NTA, about HIV/AIDs, aired on Saturday night.
He said although the country has achieved great heights with the support of government and the international community, a lot of help is still needed from private individuals to address the challenges posed by the existence of HIV/AIDs in Nigeria.
Mr. Aliyu noted that Nigeria is still the second most affected country with HIV/AIDs, globally behind South Africa. He called on government and stakeholders to ensure increased education of the girl child and women empowerment as a means of addressing the challenge.
He added that the global theme for this year's event to mark the World AIDs day, "Hands up for HIV/AIDs prevention," was adjusted for Nigeria, to match with the country's current prevalence rate of 3 per cent.
"You know that for Nigeria the topic for this year is not 'hands up'; when you say hands up you are giving up. It's 'hands on' for us in Nigeria," said Mr. Aliyu.
About 72,000 adolescents are reportedly living with HIV in Lagos State, officials have said.
Also according to the Borno State's coordinator for HIV/AIDs, no fewer than 5,000 Internally Displaced Persons, IDPs, in 27 camps in the state are currently living with the virus.
Nigeria's response to HIV aligns with global direction –NACA
A national scientific conference on HIV prevention has been organised to showcase the achievements of the response to AIDS in Nigeria.
The landmark conference organised by the National Agency for the Control of AIDS is part of activities to commemorate World AIDS Day 2016, under the theme Hands on for HIV prevention.
The conference has been slated to take place in Abuja, with participants drawn from relevant government departments and agencies, research institutions, the private sector, development partner agencies and representatives of people living with or affected by HIV.
According to the Acting Director-General of the National Agency for the Control of AIDS, Dr. Kayode Ogungbemi, the conference's theme, 'Hands on for Prevention', signifies the fact that Nigeria's national response aligns with the present global direction of increasing HIV prevention efforts.
He said, "The conference aims at showcasing the achievements, discussing the lessons learnt and seeking to set the pace for tackling prevention gaps.
"The Nigeria HIV Prevention Conference 2016 will bring together a range of experts to advance knowledge, present new research findings, as well as promote and enhance scientific and community collaborations.
"It will also be a platform for discussions on development of new strategies for addressing HIV, especially in the area of prevention."
The Chairperson, Organising Committee, Dr. Akudo Ikpeazu, added, "We welcome participants from all sectors: government, business community, civil society, academia and others.
"It is my hope that participants will all take advantage of the conference and the opportunities it presents for networking, forming new collaborations and strengthening old partnerships to strengthen HIV prevention efforts."
Presentations at the conference have been organised under four knowledge areas: behavioural, biomedical, structural, and key population issues.
Commercial Sex Workers Panic Over Turner-Helen HIV Saga
by admin - Oct 25, 2016
Fear has gripped commercial sex workers in Lagos, following reports that the 67-year-old Irish national, Mr. James Turner, accused by his 31-year-old Nigerian girlfriend of deliberately infecting her with the Human Immunodeficiency Virus, HIV, was a frequent visitor to clubs.
In fact, some of them claimed to know some of the ladies the Irish national had picked at one time or the other.
It will be recalled that Mr. Turner, was dragged to the Ikeja Police Division last week, by his Benue State-born girlfriend, Helen, after he reneged on his promise to settle her with N2.5 million, after discovering that she had been infected.
Helen, who insisted that her lover of eight years deliberately infected her with the virus, told Vanguard that she stumbled on the anti-retroviral drugs Turner was secretly taking, four months after his status was confirmed.
She also claimed to have caught Turner pants down with one of her girlfriends in his apartment, after he was confirmed to be living with HIV.
Although Turner claimed Helen infected him with the virus, he, however, told policemen during interrogation that he had so far slept with about six ladies, especially commercial sex workers, since he was confirmed to be HIV positive.
Security sources, who are said to have details of the clubs visited, refused to reveal same to Vanguard.
Helen's friend, too
Similarly, Helen's girlfriend, who she claimed Mr. Turner slept with, is also living in fear. The lady (names withheld) was said to have been informed of the development through Vanguard's publication yesterday.
She was said to have immediately visited an undisclosed hospital to confirm her status. But at press time, the result of the test could not be ascertained.
Police sources hinted that the lady could be invited in the course of the ongoing investigation.
However, Lagos State Police Public Relations Officer, Dolapo Badmus, told Vanguard yesterday that the command was still awaiting expert opinion to conclude the charge against the suspect.


text:
Four candidates to takeover at Fiorentina
3rd March 2011 Eurotips
The Gazzetta dello Sport has drawn up a list of four names as potential replacements at Fiorentina for under-fire Coach Sinisa Mihajlovic. The Serbian only got the job in the summer after Cesare Prandelli left to take the Italian national team position but his spot on the bench is in doubt after a lacklustre season. Injuries to key players have not helped his cause but Fiorentina are on course for their lowest finish since 2007.
The pink daily has given the former Bologna boss a 45% chance of retaining his position at the Stadio Artemio Franchi, which highlights the doubts surrounding the current reign.
In the lead to replace Mihajlovic is former Genoa Coach Gian Piero Gapserini, who was sacked earlier in the season. Gasperini is also rated at 45% and would be an attractive prospect because of his willingness to attack and his understanding and acceptance of younger players. La Viola would have a strong foundation for next season with their current squad in relation to Gasperini's favoured 3-4-3 formation.
Coming in behind Gasperini is former Gigliati player, Brazilian captain and Coach, Dunga, at 5%. The other two names on the list are newly unemployed Delio Rossi and Marco Giampaolo, sacked as Catania tactician before Christmas. These two have been handed a 2.5% chance each.
Van Bommel warns of difficult match against Juventus
The Ibrahimović-Pato compatibility conundrum

redpajama_set_name: RedPajamaCommonCrawl


text:
\section{Introduction}

Learning-based predictive control becomes more and more prominent in research and practice. Various approaches have been presented that underline the capabilities of (deep) learning in the context of control (see, e.g., \cite{Bradtke1994,Lewis2009,Domahidi2011,Zhong2013,Chen2018,Bhardwaj2020,Karg2020}). Most of these approaches either aim for approximations of the optimal control law in the policy space  (such as \cite{Domahidi2011,Karg2020}) or the optimal value function (or Q-function) in the value space (such as \cite{Zhong2013,Bhardwaj2020}). In both cases, suitable parametrizations for the functions to be learned have to be chosen. Common candidates are, for example, artificial neural networks (ANN) or Bayesian networks.

Choosing the type of parametrization and underlying specifications (such as layer width and depth or activation functions in ANN) is often done in a trial-and-error fashion. However, some setups support more ``educated guesses''. In fact, it has recently been shown that  certain types of ANN allow, in principle, to exactly describe model predictive control (MPC) laws for linear systems \cite{Karg2020,SchulzeDarup_2020_ECC_ANN}. The key observation here is that both the MPC law and certain ANN reflect piecewise affine (PWA) functions on polyhedral partitions. More specifically, feed-forward ANN with rectified linear units (ReLU) or max-out activations \cite{Goodfellow2013} offers this feature \cite{Montufar2014}.

Now, the optimal value function (OVF) in linear MPC is well-known to be piecewise quadratic (PWQ) \cite{Bemporad2002}. The main contribution of this paper is to show that suitable ANN can also be found for such functions. Interestingly, these ANN will also build on ReLU activations. However, successful realizations require to extend the input layer by quadratic terms of the system states (such as $\boldsymbol{x}_1^2$, $\boldsymbol{x}_2^2$, and $\boldsymbol{x}_1\boldsymbol{x}_2$). Extended inputs of this form  have also been considered elsewhere. For instance, \cite{Cheung1991} and \cite{Fan2019} exploit their ability to create non-linear decision boundaries. Clearly, this feature is not helpful here since we are dealing with polyhedral partitions. In contrast, we will use the quadratic terms to eliminate the quadratic expressions of the OVF by suitably choosing the affine preactivations. For the remaining PWA structure, we can exploit the known results mentioned above. In combination, we obtain an approach for exactly describing the OVF via ANN with ReLU activations. In addition, we present a similar approach for representing Q-functions.

The paper is organized as follows.
In Section~\ref{sec:background}, we collect preliminaries on ANN, MPC, and learning-based predictive control. Further, we briefly summarize the known representation of PWA functions using ANN. We present our main result, i.e., tailored ANN for exactly describing PWQ functions, in Section~\ref{sec:topologies}. More specifically, we construct ANN that exactly describe the OVF in linear MPC for the special case of one-dimensional states (i.e., $n=1$). Moreover, we show that ANN for describing the Q-function can be derived whenever a construction for the OVF is known  (for any $n$).
Finally, we illustrate our results with various numerical examples in Section~\ref{sec:example} and state conclusions in Section~\ref{sec:conclusion}.

\section{Preliminaries and background}
\label{sec:background}

\subsection{Neural networks with rectifier activation}
\label{subsec:neuralNetworks}

In general, a feed-forward ANN with $l\in\N$ hidden layers and $w_i$ neurons in layer $i$ can be written as a composition of the form
\begin{equation}\label{eq:ANN}
\boldsymbol{\Phi}(\boldsymbol{\xi})=\boldsymbol{f}^{(l+1)}\circ \boldsymbol{g}^{(l)}\circ \boldsymbol{f}^{(l)}\circ \dots \circ \boldsymbol{g}^{(1)}\circ \boldsymbol{f}^{(1)}(\boldsymbol{\xi}),
\end{equation}
where the functions $\boldsymbol{f}^{(i)}: \R^{w_{i-1}} \rightarrow \R^{w_i}$ refer to preactivations (for $i\leq l$) and a postactivation (for $i=l+1$) and where $\boldsymbol{g}^{(i)}: \R^{w_i} \rightarrow \R^{w_i}$ are activation functions.
The pre- and postactivations are typically affine, i.e.,
\begin{equation}
\nonumber
\boldsymbol{f}^{(i)}(\boldsymbol{y}^{(i-1)})=\boldsymbol{W}^{(i)}\boldsymbol{y}^{(i-1)}+\boldsymbol{a}^{(i)},
\end{equation}
where $\boldsymbol{W}^{(i)}\in\R^{w_i\times w_{i-1}}$ is a weighting matrix, $\boldsymbol{a}^{(i)} \in \R^{w_i}$ is a bias vector, and
 $\boldsymbol{y}^{(i-1)}$ denotes the output of the previous layer with $\boldsymbol{y}^{(0)}:=\boldsymbol{\xi}$.
Now, while various activation functions are established, we here focus on activations via ReLU that are characterized by
\begin{equation}
\nonumber
\boldsymbol{g}^{(i)}(\boldsymbol{z}^{(i)})=\max\left\{\boldsymbol{0},\boldsymbol{z}^{(i)}\right\}:=\begin{pmatrix}
\max\big\{0,\boldsymbol{z}_1^{(i)}\big\} \\
\vdots \\
\max\big\{0,\boldsymbol{z}_{w_i}^{(i)}\big\}
\end{pmatrix}.
\end{equation}
We will refer to the resulting networks as ReLU-ANN.

\subsection{Model predictive control and structural insights}

Classical MPC builds on solving an optimal control problem (OCP) of the form
\begin{align}
\label{eq:OCP}
V_N(\boldsymbol{x}) := \!\!\!\!\min_{\substack{\hat{\boldsymbol{x}}(0),...,\hat{\boldsymbol{x}}(N)\\ \hat{\boldsymbol{u}}(0),...,\hat{\boldsymbol{u}}(N-1)}}
\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! &
\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,
\varphi( \hat{\boldsymbol{x}}(N)) + \! \sum_{\kappa=0}^{N-1} \ell(\hat{\boldsymbol{x}}(\kappa),\hat{\boldsymbol{u}}(\kappa))   \\
\nonumber
\text{s.t.} \quad \quad  \hat{\boldsymbol{x}}(0)&=\boldsymbol{x}, \\
\nonumber
 \hat{\boldsymbol{x}}(\kappa+1)&=\boldsymbol{A}\,\hat{\boldsymbol{x}}(\kappa) + \boldsymbol{B} \hat{\boldsymbol{u}}(\kappa), \quad\!\!\forall \kappa \in \{0,...,N-1\}, \\
 \nonumber
\left(\hat{\boldsymbol{x}}(\kappa),\hat{\boldsymbol{u}}(\kappa)\right) & \in \Xc \times \Uc, \quad\hspace{14.9mm}\forall \kappa \in \{0,...,N-1\}, \\
 \nonumber
 \hat{\boldsymbol{x}}(N) & \in \Tc\\[-6.5mm]
 \nonumber
\end{align}
in every time step $k\in\N$ for the current state ${\boldsymbol{x}=\boldsymbol{x}(k)}$.
Here, $N\in\N$ refers to the prediction horizon and
\begin{equation}
\varphi(\boldsymbol{x}):= \boldsymbol{x}^\top \boldsymbol{P} \boldsymbol{x} \quad \text{and} \quad \ell(\boldsymbol{x},\boldsymbol{u}):=\boldsymbol{x}^\top \boldsymbol{Q} \boldsymbol{x} + \boldsymbol{u}^\top \boldsymbol{R} \boldsymbol{u}
\end{equation}
denote the terminal and stage cost, respectively,  where the weighting matrices  $\boldsymbol{P}$, $\boldsymbol{Q}$, and $\boldsymbol{R}$ are positive (semi\nobreakdash-) definite. The dynamics of the linear prediction model are described by $\boldsymbol{A}\in \R^{n \times n}$ and ${\boldsymbol{B} \in \R^{n\times m}}$. State and input constraints can be incorporated via the polyhedral sets $\Xc$ and $\Uc$. Finally, the terminal set $\Tc$ allows to enforce closed-loop stability
(see \cite{Mayne2000} for details).
The resulting control policy $\boldsymbol{\pi}:\mathcal{F}_N \rightarrow \Uc$ is defined~as
\begin{equation}
\label{eq:gMPC}
\boldsymbol{\pi}(\boldsymbol{x}):=\hat{\boldsymbol{u}}^\ast(0),
\end{equation}
where $\mathcal{F}_N$ denotes the feasible set of~\eqref{eq:OCP} and where $\hat{\boldsymbol{u}}^\ast(0)$ refers to the first element of the optimal input sequence.

Now, it is well known that $\boldsymbol{\pi}(\boldsymbol{x})$ is a (continuous) PWA function of the form
\begin{equation}\label{eq:uPWA}
\boldsymbol{\pi}(\boldsymbol{x}) = \left\{
\begin{array}{cc}
 \boldsymbol{K}^{(1)} \boldsymbol{x} + \boldsymbol{b}^{(1)} & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(1)}, \\
\vdots & \vdots \\
 \boldsymbol{K}^{(s)} \boldsymbol{x}+ \boldsymbol{b}^{(s)} & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(s)}, \\
\end{array}
\right.
\end{equation}
where the regions $\mathcal{R}^{(i)}$ represent polyhedral sets with pairwise disjoint interiors \cite[Thm.~4]{Bemporad2002}. A related observation is that the optimal value function (OVF) is a (continuous and convex) piecewise quadratic (PWQ) function of the form
\begin{equation}\label{eq:VPWQ}
V_N(\boldsymbol{x}) = \left\{
\begin{array}{cc}
\!\!\boldsymbol{x}^\top\boldsymbol{S}^{(1)}\boldsymbol{x} +\boldsymbol{x}^\top \boldsymbol{l}^{(1)} +c^{(1)} & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(1)}, \\
\vdots &  \vdots \\
\!\!\boldsymbol{x}^\top\boldsymbol{S}^{(s)}\boldsymbol{x} +\boldsymbol{x}^\top \boldsymbol{l}^{(s)} +c^{(s)} & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(s)}. \\
\end{array}
\right.\!
\end{equation}

\subsection{Learning-based predictive control}
\label{subsection:learning_for_MPC}

In principle, the structure \eqref{eq:uPWA} is quite beneficial for efficiently implementing MPC. In fact, for moderate system dimensions and prediction horizons, \eqref{eq:uPWA} can be computed explicitly and stored on the controller device.
However, for larger dimensions or horizons, this procedure is intractable. If, in addition, an online solution of the OCP is computationally too demanding, machine learning (ML) is a promising alternative. Most intuitively, ML can be used to approximate \eqref{eq:uPWA}, which refers to an approximation in the policy space.
This approach in combination with ANN of the form \eqref{eq:ANN} has, e.g., been considered in \cite{Chen2018,Karg2020}. Alternatively, one can also aim for approximating \eqref{eq:VPWQ}, i.e., an approximation in the value space \cite{Zhong2013}, \cite{Bertsekas2019book}. In fact, an (almost) optimal control input can also be inferred from (an approximation of) the OVF \cite{Lewis2009}.
Remarkably, approximating \eqref{eq:uPWA} or \eqref{eq:VPWQ} is typically realized offline using supervised learning. Hence, it usually involves the solution of \eqref{eq:OCP} for sampled states $\boldsymbol{x}$ and thus requires the knowledge of a model in terms of $\boldsymbol{A}$ and $\boldsymbol{B}$. Nevertheless, learning-based predictive control can also be realized without a model. To this end, one aims for approximating the so-called Q-function (see, e.g., \cite[P. 13]{Bertsekas2019book})
\begin{equation}\label{eq:Q-function}
Q_N(\boldsymbol{x},\boldsymbol{u}):=\ell(\boldsymbol{x},\boldsymbol{u}) + V_{N-1}(\boldsymbol{A} \boldsymbol{x} + \boldsymbol{B} \boldsymbol{u})
\end{equation}
that reflects the costs for a first step with an undetermined~$\boldsymbol{u}$ followed by an optimal control sequence of length $N-1$. We note, in this context, that the successor state ${\boldsymbol{x}^+:=\boldsymbol{A} \boldsymbol{x} + \boldsymbol{B} \boldsymbol{u}}$ can either be computed (using a model) or measured (without a model). Based on the Q-function, one can then easily derive an optimal input by evaluating $\argmin_{\boldsymbol{u}} Q_N(\boldsymbol{x},\boldsymbol{u})$. Approximating~\eqref{eq:Q-function} in the context of MPC has, e.g., been considered in \cite{Bhardwaj2020}.

\subsection{Tailored neural networks for representing PWA functions}
\label{subsection:PWA_ANN}

In this paper, we aim for tailored ANN that are capable of exactly describing the PWQ OVF \eqref{eq:VPWQ} or the Q-function~\eqref{eq:Q-function}. This goal is motivated by the observation that ReLU-ANN can, in principle, exactly describe any (continuous) PWA function of the form~\eqref{eq:uPWA} (see, e.g., \cite{Arora2018}, \cite{Hanin2017}).
However, the corresponding network topologies can quickly become intractable. For instance, the approach in \cite[Thm.~2]{Hanin2017} requires at least $s$ hidden layers, which typically results in an ANN with unfavorable depth. Useful topologies can, however, be found for special cases. In fact, for $n=1$ (and arbitrary $m$), \eqref{eq:uPWA} can exactly be described by a ReLU-ANN with one hidden layer of width $w_1=s$, i.e., by a function of the form
\begin{equation}
\label{eq:ReLUoneLayer}
   \boldsymbol{\Phi}(\boldsymbol{\xi})=\boldsymbol{W}^{(2)} \max\left\{ \boldsymbol{0}, \boldsymbol{W}^{(1)}\boldsymbol{\xi} + \boldsymbol{a}^{(1)} \right\} + \boldsymbol{a}^{(2)}
\end{equation}
with $\boldsymbol{W}^{(1)},\boldsymbol{a}^{(1)}\in \R^s$, $\boldsymbol{W}^{(2)} \in \R^{m\times s}$, and $\boldsymbol{a}^{(2)}\in \R^m$.
Suitable weights and biases are given in \cite{SchulzeDarup_2020_ECC_ANN}. Their construction builds on the trivial observation that, for one-dimensional $\boldsymbol{x}$, the regions $\mathcal{R}^{(i)}$ reflect proper intervals of the form
\begin{equation}
\label{eq:intervalRegions}
\mathcal{R}^{(i)}=[\underline{x}^{(i)},\overline{x}^{(i)}] \subset \R
\end{equation}
 that can be sorted such that $\overline{x}^{(i)}=\underline{x}^{(i+1)}$ for every $i\in \{1,\dots,s-1\}$. Using these conditions, equality of \eqref{eq:uPWA} and \eqref{eq:ReLUoneLayer} holds for the parametrization
\begin{align}
\label{eq:weightsBiasesPWA}
 \boldsymbol{W}^{(1)}\!&:=\!\begin{pmatrix}
-1 \\
\blind{+}1 \\
\blind{+}\vdots \\
\blind{+}1 \\
\end{pmatrix},
\qquad
\boldsymbol{a}^{(1)}:=\begin{pmatrix}
\blind{+}\overline{x}^{(1)} \\
-\overline{x}^{(1)} \\
\vdots \\
-\overline{x}^{(s-1)}
\end{pmatrix}, \\
\nonumber
\boldsymbol{W}^{(2)}\!&:=\!\begin{pmatrix}-\boldsymbol{K}^{(1)} & \!\boldsymbol{K}^{(2)} & \boldsymbol{K}^{(3)}\!\!-\!\boldsymbol{K}^{(2)} & \!\!\!\dots\!\!\!\! &  \boldsymbol{K}^{(s)}\!\!-\!\boldsymbol{K}^{(s-1)} \end{pmatrix}\!,\\
\nonumber
\boldsymbol{a}^{(2)}\!&:=\boldsymbol{K}^{(1)}\overline{x}^{(1)} + \boldsymbol{b}^{(1)}
\end{align}
and the choice $\boldsymbol{\xi}:=\boldsymbol{x}$ \cite[Thm.~1]{SchulzeDarup_2020_ECC_ANN}. The paper now intends to derive analogue parametrizations for describing~\eqref{eq:VPWQ} and~\eqref{eq:Q-function}.

\section{\!\!Tailored neural networks for PWQ functions}
\label{sec:topologies}

\subsection{Problem specification}

As mentioned in the introduction, our goal is to design ReLU-ANN that allow to eliminate the quadratic terms in \eqref{eq:VPWQ} or~\eqref{eq:Q-function}. In fact, the remaining functions will then be PWA and, hence, we can reuse the results from Section~\ref{subsection:PWA_ANN} for describing the remainders using further ReLU-ANN.
A formalization of this concept leads to the two following problem statements.

\begin{prob
\label{prob:ANNforOVF}
Identify an ANN of the form~\eqref{eq:ReLUoneLayer} and a mapping $\boldsymbol{h}_v: \R^n \rightarrow \R^{w_0}$ such that
\begin{equation}\label{eq:deltaV}
\Delta V_N(\boldsymbol{x}):=V_N(\boldsymbol{x})-\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x}))
\end{equation}
is PWA in $\boldsymbol{x}$.
\end{prob}

\begin{prob
\label{prob:ANNforQfun}
Identify an ANN of the form~\eqref{eq:ReLUoneLayer} and a mapping $\boldsymbol{h}_q: \R^n \times \R^m \rightarrow \R^{w_0}$ such that
\begin{equation}
\label{eq:deltaQ}
  \Delta Q_N(\boldsymbol{x},\boldsymbol{u}):=Q_N(\boldsymbol{x},\boldsymbol{u})-\boldsymbol{\Phi}(\boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u}))
\end{equation}
is PWA in $\boldsymbol{x}$ and $\boldsymbol{u}$.
\end{prob}

Here, it is import to note that choosing suitable network inputs via $\boldsymbol{h}_v$ and $\boldsymbol{h}_q$ is part of the problems. In fact, the naive choices $\boldsymbol{\xi}:=\boldsymbol{x}$ as in Section~\ref{subsection:PWA_ANN} or $\boldsymbol{\xi}^\top:=(\,
\boldsymbol{x}^\top \,\,\, \boldsymbol{u}^\top \,)^\top$ will, in general, not solve the problems.
We further note that both $V_N$ and $Q_N$ are scalar-valued functions. Hence, also the desired $\boldsymbol{\Phi}$ is scalar-valued in both cases and the corresponding parameters have the dimensions $\boldsymbol{W}^{(1)}\! \in \R^{w_1 \times w_0}$, $\boldsymbol{a}^{(1)}\!\in \R^{w_1}$, $\boldsymbol{W}^{(2)}\! \in \R^{1\times w_1}$, and $\boldsymbol{a}^{(2)}\!\in \R$.
We still use bold characters for $\boldsymbol{\Phi}$ and $\boldsymbol{a}^{(2)}$ for consistency.

In the following, we present (partial) solutions to Problems~\ref{prob:ANNforOVF} and~\ref{prob:ANNforQfun}. More precisely, we solve Problem~\ref{prob:ANNforOVF} for the special case $n=1$ that has also been addressed in \cite{SchulzeDarup_2020_ECC_ANN} for the PWA analogue. Further, we show that a solution to Problem~\ref{prob:ANNforQfun} can be derived from a given solution to Problem~\ref{prob:ANNforOVF} for arbitrary $n\geq 1$.

\subsection{Solution to Problem 1 for $n=1$}

The following theorem provides a solution to Problem~\ref{prob:ANNforOVF} for one-dimensional system states. The underlying construction is based on the observation that ReLU can be designed to be active only inside one of the regions~\eqref{eq:intervalRegions}.

\begin{thm}
\label{thm:sol1}
Let $n=1$ and assume that the regions $\mathcal{R}^{(i)}$ are as in~\eqref{eq:intervalRegions} (with $\underline{x}^{(i)}<\overline{x}^{(i)}=\underline{x}^{(i+1)}$) and bounded. Then, a solution to Problem~\ref{prob:ANNforOVF} is given in terms of
\begin{align*}
    \boldsymbol{W}^{(1)}&:=\begin{pmatrix}
\underline{x}^{(1)}+\overline{x}^{(1)} & -1 \\
\vdots & \vdots \\
\underline{x}^{(s)}+\overline{x}^{(s)} & -1 \\
\end{pmatrix}, & \boldsymbol{a}^{(1)}&:=\begin{pmatrix}
-\underline{x}^{(1)} \overline{x}^{(1)} \\
\vdots \\
-\underline{x}^{(s)} \overline{x}^{(s)}
\end{pmatrix}, \\
\boldsymbol{W}^{(2)}&:=\begin{pmatrix}
-\boldsymbol{S}^{(1)} & \dots & -\boldsymbol{S}^{(s)}
\end{pmatrix}, & \boldsymbol{a}^{(2)}&:=0
\end{align*}
and the mapping $\boldsymbol{h}_v(\boldsymbol{x}) := \begin{pmatrix}
\boldsymbol{x} & \boldsymbol{x}^2 \end{pmatrix}^\top$.
\end{thm}

\vspace{1mm}
\begin{proof}
We obviously have
$$
(\underline{x}^{(i)}+\overline{x}^{(i)}) \boldsymbol{x} - \boldsymbol{x}^2 -\underline{x}^{(i)} \overline{x}^{(i)}=  (\boldsymbol{x}-\underline{x}^{(i)})(\overline{x}^{(i)}-\boldsymbol{x}).
$$
Hence, the proposed parametrization yields
\begin{equation}\label{eq:1D_quad_ReLU}
\!\,\,\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x}))=\!\sum\limits_{i=1}^s\!-\boldsymbol{S}^{(i)} \max \left\{0, (\boldsymbol{x}-\underline{x}^{(i)}) (\overline{x}^{(i)}-\boldsymbol{x}) \right\}\!.\!\!\!\!\!
\end{equation}
Clearly, $(\boldsymbol{x}-\underline{x}^{(i)}) (\overline{x}^{(i)}-\boldsymbol{x})> 0$ if and only if the conditions
\begin{equation}
\label{eq:xBounds1}
   \boldsymbol{x}-\underline{x}^{(i)} > 0 \quad \text{and} \quad \overline{x}^{(i)}-\boldsymbol{x} > 0
\end{equation}
or
\begin{equation}
\label{eq:xBounds2}
\boldsymbol{x}-\underline{x}^{(i)} < 0 \quad \text{and} \quad \overline{x}^{(i)}-\boldsymbol{x} < 0
\end{equation}
hold.
Now, conditions~\eqref{eq:xBounds1} are  equivalent to ${\boldsymbol{x} \in \mathrm{int}\big(\mathcal{R}^{(i)}\big)}$ and conditions~\eqref{eq:xBounds2} are infeasible for proper intervals with $\underline{x}^{(i)}<\overline{x}^{(i)}$.
Since we further have $\mathrm{int}\big(\mathcal{R}^{(i)}\big)\cap \mathrm{int}\big(\mathcal{R}^{(j)}\big)=\emptyset$ whenever $i\neq j$, we obtain
$$
\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x})) = \left\{
\begin{array}{lc}
-\boldsymbol{S}^{(1)} (\boldsymbol{x}-\underline{x}^{(i)}) (\overline{x}^{(i)}-\boldsymbol{x})  & \text{if} \ \boldsymbol{x}\in\mathcal{R}^{(1)}, \\
\quad\vdots & \vdots  \\
-\boldsymbol{S}^{(s)} (\boldsymbol{x}-\underline{x}^{(i)}) (\overline{x}^{(i)}-\boldsymbol{x}) & \text{if} \ \boldsymbol{x}\in\mathcal{R}^{(s)}, \\
\end{array}
\right.
$$
where $\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x}))=0$ results whenever $\boldsymbol{x}$ is located on the boundary of any $\mathcal{R}^{(i)}$.  Evaluating \eqref{eq:deltaV} finally results in the PWA function
\begin{equation}
\label{eq:deltaV_PWA}
\Delta V_N(\boldsymbol{x}) = \left\{
\begin{array}{lc}
\kappa^{(1)} \boldsymbol{x} +\beta^{(1)}& \text{if} \ \boldsymbol{x}\in\mathcal{R}^{(1)}, \\
\quad\vdots & \vdots  \\
\kappa^{(s)} \boldsymbol{x} +\beta^{(s)}& \text{if} \ \boldsymbol{x}\in\mathcal{R}^{(s)}\blind{,} \\
\end{array}
\right.
\end{equation}
with the parameters $\kappa^{(i)}:=\boldsymbol{l}^{(i)} + \boldsymbol{S}^{(i)} (\underline{x}^{(i)}+\overline{x}^{(i)})$ and $\beta^{(i)}:=c^{(i)} - \boldsymbol{S}^{(i)} \underline{x}^{(i)}\overline{x}^{(i)}$, which completes the proof.
\end{proof}

Roughly speaking, Theorem~\ref{thm:sol1} provides a ReLU-ANN that reflects the quadratic terms of $V_N(\boldsymbol{x})$. In fact, we proved that the difference~\eqref{eq:deltaV} is PWA.
Now, as summarized in Section~\ref{subsection:PWA_ANN}, it has been known before that PWA functions can likewise be described by ReLU-ANN with one hidden layer. Thus, by combining both results, we can construct a ReLU-ANN of the form \eqref{eq:ReLUoneLayer} that completely reflects $V_N(\boldsymbol{x})$. However, when applying the results from Section~\ref{subsection:PWA_ANN}, one has to take into account that representing the quadratic terms requires $\boldsymbol{\xi}=\boldsymbol{h}_v(\boldsymbol{x})$. Fortunately, $\boldsymbol{h}_v(\boldsymbol{x})$ contains the state~$\boldsymbol{x}$. Hence, we can easily adapt the parametrization from~\eqref{eq:weightsBiasesPWA} according to the following Corollary.

\begin{cor}
\label{cor:ANNforDeltaV}
Let $\boldsymbol{h}_v$ and $\Delta V_N$ be as in Theorem~\ref{thm:sol1} and \eqref{eq:deltaV_PWA}, respectively. Then,  $\Delta V_N(\boldsymbol{x})=\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x}))$ holds for an ANN as in \eqref{eq:ReLUoneLayer} with the parameters
\begin{align*}
 \boldsymbol{W}^{(1)}&:=\begin{pmatrix}
-1 & 0\\
\blind{+}1 & 0 \\
\blind{+}\vdots & \vdots \\
\blind{+}1 & 0 \\
\end{pmatrix},
\qquad
\boldsymbol{a}^{(1)}:=\begin{pmatrix}
\blind{+}\overline{x}^{(1)} \\
-\overline{x}^{(1)} \\
\vdots \\
-\overline{x}^{(s-1)}
\end{pmatrix}, \\
\nonumber
\boldsymbol{W}^{(2)}&:=\begin{pmatrix}-\kappa^{(1)} & \!\kappa^{(2)} & \kappa^{(3)}\!-\!\kappa^{(2)} & \!\!\dots\!\!\! &  \kappa^{(s)}\!-\!\kappa^{(s-1)} \end{pmatrix}\!,\\
\nonumber
\boldsymbol{a}^{(2)}&:=\kappa^{(1)}\overline{x}^{(1)} + \beta^{(1)}.
\end{align*}
\end{cor}

\vspace{2mm}
The combination of Theorem~\ref{thm:sol1} and Corollary \ref{cor:ANNforDeltaV} leads to the following summarizing statement. An illustration with an example will follow in Section \ref{subsec:ex_OVF}.

\begin{cor}
\label{cor:ANNforV}
Let $n=1$. Then, $V_N$ as in~\eqref{eq:VPWQ} can be exactly described by a ReLU-ANN with one hidden layer of width $w_1=2s$ and the inputs
 $\boldsymbol{\xi}=\begin{pmatrix} \boldsymbol{x} & \boldsymbol{x}^2 \end{pmatrix}^\top$\!.
\end{cor}

\subsection{Conditional solution to Problem 2 for arbitrary $n$}

Interestingly, the Problems~\ref{prob:ANNforOVF} and~\ref{prob:ANNforQfun} are closely related. In fact, the following theorem shows that a solution to the former problem implies a solution to the latter. In other words, an ANN representing the OVF can be easily adapted for describing the Q-function.

\begin{thm}
\label{thm:sol1ImpliesSol2}
Assume Problem~\ref{prob:ANNforOVF} has been solved for $N^\prime=N-1$ and let $\boldsymbol{W}^{(1)}_v$,  $\boldsymbol{W}^{(2)}_v$, $\boldsymbol{a}_v^{(1)}$, and $\boldsymbol{a}_v^{(2)}$ denote the corresponding weights and biases in~\eqref{eq:ReLUoneLayer}. Then, a solution to Problem~\ref{prob:ANNforQfun} is given in terms of
\begin{subequations}
\label{eq:Wa_QFun}
\begin{align}
  \boldsymbol{W}^{(1)}&:=\begin{pmatrix}
\boldsymbol{W}^{(1)}_v & \boldsymbol{0} \\
\boldsymbol{0} & 1
\end{pmatrix}, & \boldsymbol{a}^{(1)}&:=\begin{pmatrix}
\boldsymbol{a}^{(1)}_v  \\
0
\end{pmatrix},\\
\boldsymbol{W}^{(2)}&:=\begin{pmatrix}
\boldsymbol{W}^{(2)}_v & 1
\end{pmatrix}, & \boldsymbol{a}^{(2)} &:=\boldsymbol{a}^{(2)}_v
\end{align}
\end{subequations}
and the mapping
\begin{equation}
\label{eq:hqNaiv}
  \boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u}):=\begin{pmatrix}
\boldsymbol{h}_v(\boldsymbol{A}\boldsymbol{x}+\boldsymbol{B} \boldsymbol{u}) \\
\ell(\boldsymbol{x},\boldsymbol{u})
\end{pmatrix}.
\end{equation}
\end{thm}

\begin{proof}
The assumed solution to Problem~\ref{prob:ANNforOVF} implies
\begin{align*}
 V_{N-1}(\boldsymbol{x})&=\boldsymbol{W}_v^{(2)} \max\left\{ \boldsymbol{0}, \boldsymbol{W}_v^{(1)} \boldsymbol{h}_v(\boldsymbol{x}) + \boldsymbol{a}_v^{(1)} \right\}  \\
 &\quad + \boldsymbol{a}_v^{(2)} +\Delta V_{N-1}(\boldsymbol{x})
\end{align*}
with $\Delta V_{N-1}(\boldsymbol{x})$ being PWA in $\boldsymbol{x}$. Hence, the Q-function \eqref{eq:Q-function} can be written as
\begin{align*}
Q_N(\boldsymbol{x},\boldsymbol{u}) &= \boldsymbol{W}_v^{(2)} \max\left\{ \boldsymbol{0}, \boldsymbol{W}_v^{(1)} \boldsymbol{h}_v(\boldsymbol{A}\boldsymbol{x}+\boldsymbol{B} \boldsymbol{u}) + \boldsymbol{a}_v^{(1)} \right\} \\
&\quad + \boldsymbol{a}_v^{(2)} +\Delta V_{N-1}(\boldsymbol{A}\boldsymbol{x}+\boldsymbol{B} \boldsymbol{u}) + \ell(\boldsymbol{x},\boldsymbol{u}).
\end{align*}
Now, the proposed solution to~\ref{prob:ANNforQfun} involves the ANN
$$
\boldsymbol{\Phi}(\boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u}))=\boldsymbol{W}^{(2)} \max\left\{ \boldsymbol{0}, \boldsymbol{W}^{(1)} \boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u}) + \boldsymbol{a}^{(1)} \right\} + \boldsymbol{a}^{(2)}.
$$
Hence, substituting the proposed weights and biases and evaluating \eqref{eq:deltaQ} results in
\begin{align}
\nonumber
\Delta Q_N(\boldsymbol{x},\boldsymbol{u}) & = \Delta V_{N-1}(\boldsymbol{A}\boldsymbol{x}+\boldsymbol{B} \boldsymbol{u}) + \ell(\boldsymbol{x},\boldsymbol{u})\\
\label{eq:deltaQViaDeltaV}
&\quad -\max\{0,\ell(\boldsymbol{x},\boldsymbol{u})\}.
\end{align}
Clearly, $\Delta V_{N-1}(\boldsymbol{A}\boldsymbol{x}+\boldsymbol{B} \boldsymbol{u})$ is PWA in $\boldsymbol{x}$ and $\boldsymbol{u}$. This completes the proof since $\ell(\boldsymbol{x},\boldsymbol{u}) -\max\{0,\ell(\boldsymbol{x},\boldsymbol{u})\}=0$ due to positive semi-definiteness of $\ell$.
\end{proof}

From a theoretical point of view, Theorem~\ref{thm:sol1ImpliesSol2} is quite useful since it closely relates Problems~\ref{prob:ANNforOVF} and~\ref{prob:ANNforQfun}. Unfortunately, from a practical point of view, the proposed mapping~\eqref{eq:hqNaiv} is not convenient. In fact, $Q$-learning allows model-free learning but evaluating~\eqref{eq:hqNaiv} (for data preparation) requires a model in terms of $\boldsymbol{A}$ and~$\boldsymbol{B}$. Fortunately, this issue can be easily solved.
To this end, we assume that the solution to Problem~\ref{prob:ANNforOVF} builds on the mapping
\begin{equation}
\label{eq:hvStructure}
   \boldsymbol{h}_v(\boldsymbol{x}):=\begin{pmatrix}
\boldsymbol{x}^\top & \boldsymbol{x}_1^2 &\boldsymbol{x}_1 \boldsymbol{x}_2 & \!\dots\! & \boldsymbol{x}_1 \boldsymbol{x}_n  & \!\dots\!& \boldsymbol{x}_n^2
\end{pmatrix}^\top\!\!\!,\!
\end{equation}
i.e., an extension of the state $\boldsymbol{x}$ by all possible products of two individual states. We note that this assumption is reasonable for various reasons. First, \eqref{eq:hvStructure} includes our solution for the one-dimensional case in Theorem~\ref{thm:sol1}. Second, similar approaches have been considered for (loosely) related problems \cite{Bradtke1994,Fan2019}. Third, we show in Section~\ref{subsection:2D_example} that \eqref{eq:hvStructure} also applies to exemplary extensions with $n>1$. Now, the structure of~\eqref{eq:hvStructure} can be easily extended to the $\boldsymbol{x}$-$\boldsymbol{u}$-domain yielding the mapping
\begin{equation}
\label{eq:hqPrime}
  \boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u}):=\begin{pmatrix}
\boldsymbol{h}_v(\boldsymbol{x}) \\
\boldsymbol{u} \\
\boldsymbol{u}_1 \boldsymbol{u}_2 \\
\vdots \\
\boldsymbol{u}_m^2 \\
\boldsymbol{x}_1 \boldsymbol{u}_1 \\
\vdots \\
\boldsymbol{x}_n \boldsymbol{u}_m
\end{pmatrix}
\end{equation}
that includes, in addtion to $\boldsymbol{x}$ and $\boldsymbol{u}$, all possible products of two entries in $(\,\boldsymbol{x}^\top \,\,\,\boldsymbol{u}^\top\,)$.
As shown next, there exists a linear relation between $\boldsymbol{h}_q$ from Theorem~\ref{thm:sol1ImpliesSol2} and $\boldsymbol{h}^\prime_q$ as in~\eqref{eq:hqPrime}.

\begin{lem}
\label{lem:hqReplacementViaL}
There exists a matrix $\boldsymbol{L} \in \R^{w_0 \times w_0^\prime}$ such that
\begin{equation}
\label{eq:hqViaL}
    \boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u}) = \boldsymbol{L} \boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u}),
\end{equation}
where $w_0:=n(n+3)/2+1$ and $w_0^\prime:=(n+m)(n+m+3)/2$.
\end{lem}

\begin{proof}
Clearly, each entry in ${\boldsymbol{h}_v(\boldsymbol{A} \boldsymbol{x} +\boldsymbol{B} \boldsymbol{u})}$ can be written as a linear combination of the entries in $\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u})$. The same observation holds for $\ell(\boldsymbol{x},\boldsymbol{u})$. The corresponding coefficients form the entries of $\boldsymbol{L}$. The dimensions $w_0$ and $w_0^\prime$ simply reflect the output dimensions of $\boldsymbol{h}_q$ and $\boldsymbol{h}^\prime_q$.
\end{proof}

Relation~\eqref{eq:hqViaL} allows to reformulate the statement in Theorem~\ref{thm:sol1ImpliesSol2} using the more convenient network inputs $\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u})$. In fact, as specified in the following corollary, the matrix $\boldsymbol{L}$ can simply be including in the construction~of~$\boldsymbol{W}^{(1)}$.

\begin{cor}\label{cor:WL}
Consider the same solution to Problem~\ref{prob:ANNforOVF} as in Theorem~\ref{thm:sol1ImpliesSol2}. Further, let $\boldsymbol{L}$ satisfy~\eqref{eq:hqViaL}.
Then, a solution to Problem~\ref{prob:ANNforQfun} can be obtained analogously to Theorem~\ref{thm:sol1ImpliesSol2} except that $\boldsymbol{W}^{(1)}$ and $\boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u})$ are replaced by
$$
\boldsymbol{W}^{(1)}:=\begin{pmatrix}
\boldsymbol{W}^{(1)}_v & \boldsymbol{0} \\
\boldsymbol{0} & 1
\end{pmatrix} \boldsymbol{L}
$$
and $\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u})$, respectively.
\end{cor}

Inspired by Corollaries \ref{cor:ANNforDeltaV} and \ref{cor:ANNforV}, we could now aim for statements about suitable ReLU-ANN for describing $\Delta Q_N$ and~$Q_N$, respectively.
However, Theorem~\ref{thm:sol1ImpliesSol2} assumes a solution to Problem~\ref{prob:ANNforOVF} and it is unclear whether such a solution exists for $n>1$ and, if it exists, how it is structured.
Thus, we only provide the following statement for $n=1$.

\begin{cor}
\label{cor:ANNforQ}
Let $n=1$ and assume $V_{N-1}$ is defined on~$s^\prime$ regions. Then, $Q_N$ as in~\eqref{eq:Q-function} can be exactly described by a ReLU-ANN with one hidden layer of width $w_1=2s^\prime+1$ and the inputs
 $\boldsymbol{\xi}=\boldsymbol{h}_q^\prime(\boldsymbol{x},\boldsymbol{u})$.
\end{cor}

\begin{proof}
We know from Theorem~\ref{thm:sol1} that Problem~\ref{prob:ANNforOVF} can be solved for $N^\prime=N-1$ based on a ReLU-ANN with one hidden layer of width $s^\prime$. Now, Theorem~\ref{thm:sol1ImpliesSol2} tells us that adding one neuron allows us to solve Problem~\ref{prob:ANNforQfun}. From~\eqref{eq:deltaQViaDeltaV}, we further infer that the resulting PWA $\Delta Q_N(\boldsymbol{x},\boldsymbol{u})$ is equivalent to $\Delta V_{N-1}(\boldsymbol{A}\boldsymbol{x}+\boldsymbol{B} \boldsymbol{u})$. Corollary~\ref{cor:ANNforDeltaV} shows that another $s^\prime$ neurons are required to represent $\Delta V_{N-1}$, which already leads to the proposed width of $2s^\prime+1$. It remains to comment on suitable inputs for the ANN. In this context, we first note that $\boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u})$ from Theorem~\ref{thm:sol1ImpliesSol2} contains $\boldsymbol{A} \boldsymbol{x} + \boldsymbol{B} \boldsymbol{u}$ for $\boldsymbol{h}_v$ as in~\eqref{eq:hvStructure}. Hence, $\Delta V_{N-1}(\boldsymbol{A}\boldsymbol{x}+\boldsymbol{B} \boldsymbol{u})$ can be described based on the ReLU-ANN for $\Delta V_{N-1}$ with the inputs $\boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u})$. This completes the proof since Lemma~\ref{lem:hqReplacementViaL} implies that the inputs $\boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u})$ can easily be replaced by $\boldsymbol{\xi}=\boldsymbol{h}_q^\prime(\boldsymbol{x},\boldsymbol{u})$ without changing the width $w_1$.
\end{proof}

\section{Numerical examples}
\label{sec:example}
We illustrate (and extend) our results with four numerical examples. The two first examples demonstrate the application of Theorems~\ref{thm:sol1} and~\ref{thm:sol1ImpliesSol2}. Moreover, we point out the benefits of the proposed ANN for learning the Q-function. The last example shows a possible direction for an open extension to systems with $n>1$.

\vspace{-1mm}

\subsection{Exact representation of the optimal value function}\label{subsec:ex_OVF}

We consider the system from \cite[Ex.~2]{SchulzeDarup2016_ECC_MPC}
with the dynamics
\begin{equation}\label{eq:example_1D_system}
\boldsymbol{x}(k+1)=\tfrac{6}{5}\boldsymbol{x}(k)+\boldsymbol{u}(k)\\
\end{equation}
and the constraints $\boldsymbol{x} \in [-10,10]\subset \R$ and $\boldsymbol{u}  \in [-1,1]\subset \R$.  As in \cite{SchulzeDarup2016_ECC_MPC}, we choose $\boldsymbol{Q}=19/5$, $\boldsymbol{R}=1$, $\boldsymbol{P}=5$, and $\Tc=[-1,1]$. Finally, we select $N=1$ for illustration purposes here.
Explicitly solving \eqref{eq:OCP} then leads to
\begin{equation}\label{eq:example1_V1}
V_1(\boldsymbol{x}) = \left\{
\begin{array}{lll}
11\boldsymbol{x}^2+12\boldsymbol{x}+6 & \text{if} & \boldsymbol{x}\in\mathcal{R}^{(1)}, \\
5\boldsymbol{x}^2 & \text{if} & \boldsymbol{x}\in\mathcal{R}^{(2)}, \\
11\boldsymbol{x}^2-12\boldsymbol{x}+6 & \text{if} & \boldsymbol{x}\in\mathcal{R}^{(3)},
\end{array}
\right.
\end{equation}
where the three regions refer to the intervals
$$
  \mathcal{R}^{(1)}=\left[-\tfrac{5}{3},-1\right], \quad \mathcal{R}^{(2)}=\left[-1,1\right], \quad
\mathcal{R}^{(3)}=\left[1,\tfrac{5}{3}\right].
$$
Now, according to Theorem~\ref{thm:sol1}, a solution to Problem~\ref{prob:ANNforOVF} is given in terms of the parameters
\begin{subequations}
\label{eq:Wa_Ex1_V1}
\begin{align}
\boldsymbol{W}_v^{(1)}&:=\begin{pmatrix}
-\frac{8}{3} & -1 \\
\blind{+} 0 & -1 \\
\blind{+} \frac{8}{3} & -1 \\
\end{pmatrix}, &
\boldsymbol{a}_v^{(1)}&:=\begin{pmatrix}
-\frac{5}{3} \\
\blind{+} 1 \\
-\frac{5}{3} \\
\end{pmatrix}, \\
\boldsymbol{W}_v^{(2)}&:=\begin{pmatrix}
-11 & -5 & -11
\end{pmatrix}, &
\boldsymbol{a}_v^{(2)} &:= 0
\end{align}
\end{subequations}
and the mapping $\boldsymbol{h}_v(\boldsymbol{x}):=(\,\boldsymbol{x}\,\,\,\boldsymbol{x}^2\,)^\top$. Figure~\ref{fig:V1} confirms this result by visualizing the PWA $\Delta V_1$.
We can further exploit the structure of $\Delta V_1$ based on Corollary~\ref{cor:ANNforDeltaV}. In fact, with $\kappa^{(i)}$ and $\beta^{(i)}$ as in the proof of Theorem~\ref{thm:sol1}, we find that $\Delta V_1$ can be described as an ANN of the form~\eqref{eq:ReLUoneLayer} with the parameters
\begin{subequations}
\label{eq:Wa_DeltaV_Ex1}
\begin{align}
\boldsymbol{W}_\Delta^{(1)}&:=\begin{pmatrix}
-1 & 0\\
\blind{+} 1 & 0 \\
\blind{+} 1 & 0
\end{pmatrix}, &
\boldsymbol{a}_\Delta^{(1)}&:=\left(\begin{array}{c}
-1 \\
\blind{+} 1 \\
-1
\end{array}\right), \\
\boldsymbol{W}_\Delta^{(2)}&:=\left(\begin{array}{ccccc}
 \frac{52}{3} & 0 & \frac{52}{3}
\end{array}\right), & \boldsymbol{a}_\Delta^{(2)} &:= 5.
\end{align}
\end{subequations}
By combining both results, we can construct a ReLU-ANN that exactly describes $V_1$. In fact, the parametrization
\begin{align*}
\boldsymbol{W}^{(1)}&:=\begin{pmatrix}
\boldsymbol{W}_v^{(1)} \\
\boldsymbol{W}_\Delta^{(1)}
\end{pmatrix}, &
\boldsymbol{a}^{(1)}&:=\begin{pmatrix}
\boldsymbol{a}_v^{(1)} \\
\boldsymbol{a}_\Delta^{(1)}
\end{pmatrix}, \\
\boldsymbol{W}^{(2)}&:=\begin{pmatrix}
\boldsymbol{W}_v^{(2)} & \boldsymbol{W}_\Delta^{(2)}
\end{pmatrix}, &
\boldsymbol{a}^{(2)} &:= \boldsymbol{a}_\Delta^{(2)}
\end{align*}
leads to $V_1(\boldsymbol{x})=\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x}))$ and thus confirms Corollary~\ref{cor:ANNforV}.

\begin{figure}[h]
\centering
\includegraphics[trim={3cm 11cm 3cm 11cm},clip,scale=0.5]{fig1.pdf}
\caption{Illustration of the PWQ function $V_1$ (black), the proposed ANN for the quadratic terms (blue), and the PWA difference $\Delta V_1$ (red) for the example in Section~\ref{subsec:ex_OVF}.}
\label{fig:V1}
\end{figure}

\vspace{-5mm}

\subsection{Adaptation for Q-function}\label{subsec:ex_Q-function}

We next illustrate the application of Theorem~\ref{thm:sol1ImpliesSol2}. In order to reuse the results from the previous example, we consider $N=2$ here and consequently the Q-function
\begin{equation}
Q_2(\boldsymbol{x},\boldsymbol{u})=\ell(\boldsymbol{x},\boldsymbol{u}) + V_1\left(\tfrac{6}{5} \boldsymbol{x} + \boldsymbol{u}\right)
\end{equation}
with $V_1$ as in~\eqref{eq:example1_V1}.
Now, according to Theorem~\ref{thm:sol1ImpliesSol2}, a solution to Problem~\ref{prob:ANNforQfun} can be obtained by substituting~\eqref{eq:Wa_Ex1_V1} in~\eqref{eq:Wa_QFun} and by considering the mapping
$$
\boldsymbol{h}_q(\boldsymbol{x},\boldsymbol{u}):=\begin{pmatrix}
\boldsymbol{h}_v\big(\frac{6}{5} \boldsymbol{x} + \boldsymbol{u}\big) \\[1mm]
\ell(\boldsymbol{x},\boldsymbol{u})
\end{pmatrix} = \begin{pmatrix}
\frac{6}{5} \boldsymbol{x} + \boldsymbol{u} \\
\frac{36}{25} \boldsymbol{x}^2 + \frac{12}{5} \boldsymbol{x} \boldsymbol{u} + \boldsymbol{u}^2 \\
\frac{19}{5} \boldsymbol{x}^2 + \boldsymbol{u}^2
\end{pmatrix}.
$$
Clearly, evaluating this mapping requires the model~\eqref{eq:example_1D_system}.
Fortunately, Lemma~\ref{lem:hqReplacementViaL} and Corollary~\ref{cor:WL} tell us that we can easily switch to the more convenient network inputs
\begin{equation}
\label{eq:hqPrime_Ex2}
\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u}):=\begin{pmatrix}
\boldsymbol{x} &
\boldsymbol{x}^2 &
\boldsymbol{u} &
\boldsymbol{u}^2 &
\boldsymbol{x} \boldsymbol{u}
\end{pmatrix}^\top\!.
\end{equation}
To this end, we quickly verify that~\eqref{eq:hqViaL} is satisfied by
$$
\boldsymbol{L} =\begin{pmatrix}
\frac{6}{5} & 0 & 1 & 0 & 0 \\[.5ex]
0 & \frac{36}{25} & 0 & 1 & \frac{12}{5} \\[.5ex]
0 & \frac{19}{5} & 0 & 1 & 0 \\
\end{pmatrix}.
$$
Hence, Theorem~\ref{thm:sol1ImpliesSol2} in combination with the parameters~\eqref{eq:Wa_Ex1_V1} and Corollary~\ref{cor:WL} implies that Problem~\ref{prob:ANNforQfun} is solved by
\begin{align*}
\boldsymbol{W}_q^{(1)}\!&:=\!\begin{pmatrix}
-\frac{16}{5} & \!-\frac{36}{25} & \!-\frac{8}{3} & \!-1 & -\frac{12}{5} \\[.5ex]
\blind{+}0 & \!-\frac{36}{25} & \!\blind{+} 0 & \!-1 & -\frac{12}{5} \\[.5ex]
\blind{+}\frac{16}{5} & \!-\frac{36}{25} & \!\blind{+}\frac{8}{3} & \!-1 & -\frac{12}{5} \\[.5ex]
\blind{+}0 & \!\blind{+}\frac{19}{5} & \!\blind{+}0 & \!\blind{+}1 & \blind{+} 0
\end{pmatrix}\!, &
\!\!\!\boldsymbol{a}_q^{(1)}&:=\begin{pmatrix}
-\frac{5}{3} \\
\blind{+} 1 \\
-\frac{5}{3} \\
\blind{+} 0 \\
\end{pmatrix}\!, \\
\boldsymbol{W}_q^{(2)}\!&:=\begin{pmatrix}
-11 & -5 & -11 & 1
\end{pmatrix}, &
\!\!\!\boldsymbol{a}_q^{(2)} &:= 0.
\end{align*}
and the mapping~\eqref{eq:hqPrime_Ex2}.
In order to describe the entire Q-function, it remains to construct an ANN for $\Delta Q_2(\boldsymbol{x},\boldsymbol{u})=\Delta V_1(\boldsymbol{A} \boldsymbol{x}+ \boldsymbol{B} \boldsymbol{u})$. Clearly, we can reuse the parametrization for $\Delta V_1$ from~\eqref{eq:Wa_DeltaV_Ex1}. However, we have to include a matrix that selects $\boldsymbol{A} \boldsymbol{x}+ \boldsymbol{B} \boldsymbol{u}$ from $\boldsymbol{h}_q$ and we have to take into account the switching to $\boldsymbol{h}_q^\prime$ via $\boldsymbol{L}$. Doing so, we can easily confirm that $\Delta V_1(\boldsymbol{A} \boldsymbol{x}+ \boldsymbol{B} \boldsymbol{u})=\boldsymbol{\Phi}(\boldsymbol{h}_q^\prime(\boldsymbol{x},\boldsymbol{u}))$ holds for
$$
\boldsymbol{W}^{(1)}_\delta:=
\boldsymbol{W}^{(1)}_\Delta \begin{pmatrix} 1 & 0 & 0 \\
1 & 0 & 0 \\
\end{pmatrix} \boldsymbol{L}=
\begin{pmatrix}
-\frac{6}{5} & 0 & -1 & 0 & 0 \\[.5ex]
\blind{+}\frac{6}{5} & 0 & \blind{+}1 & 0 & 0 \\[.5ex]
\blind{+}\frac{6}{5} & 0 & \blind{+}1 & 0 & 0 \\
\end{pmatrix},
$$
$$\boldsymbol{a}^{(1)}_\delta:=\boldsymbol{a}^{(1)}_\Delta, \ \boldsymbol{W}^{(2)}_\delta:=\boldsymbol{W}_\Delta^{(2)}, \ \text{and} \ \boldsymbol{a}^{(2)}_\delta:=\boldsymbol{a}^{(2)}_\Delta.$$
Combining the solution to Problem~\ref{prob:ANNforQfun} and the description of $\Delta Q_2$ from above leads to a ReLU-ANN for $Q_2$ with the parameters
\begin{align*}
\boldsymbol{W}^{(1)}&:=\begin{pmatrix}
\boldsymbol{W}_q^{(1)} \\
\boldsymbol{W}_\delta^{(1)}
\end{pmatrix}, &
\boldsymbol{a}^{(1)}&:=\begin{pmatrix}
\boldsymbol{a}_q^{(1)} \\
\boldsymbol{a}_\delta^{(1)}
\end{pmatrix}, \\
\boldsymbol{W}^{(2)}&:=\begin{pmatrix}
\boldsymbol{W}_q^{(2)} & \boldsymbol{W}_\delta^{(2)}
\end{pmatrix}, &
\boldsymbol{a}^{(2)} &:= \boldsymbol{a}_\delta^{(2)}
\end{align*}
and the inputs $\boldsymbol{h}_q^\prime(\boldsymbol{x},\boldsymbol{u})$. As predicted by Corollary~\ref{cor:ANNforQ}, this ANN has one hidden layer of width $w_1=2s^\prime+1=7$.

\subsection{Learning of the Q-function}\label{subsection:example_learn_Q}

The presented work is motivated by the observation that, in the context of learning, ANN topologies are often chosen based on trial-and-error. Our results show that, for MPC-related learning, more educated choices exist that even allow to exactly describe the functions of interest. Interestingly, the identified topologies (summarized in the Corollaries~\ref{cor:ANNforV} and~\ref{cor:ANNforQ}) seem to be useful beyond the proposed exact descriptions. To substantiate this observation, we investigated different learning-based approximations of $Q_2$ from the previous example. More precisely, we trained various ReLU-ANN with different inputs, widths, and depths (using supervised learning and Matlab's Deep Learning Toolbox \cite{MatlabDeepLearning} for simplicity) over $1000$ epochs. We repeated the training 100 times for each ReLU-ANN, where we used the same randomly sampled points from the Q-function as training data for every trial. At the end of every trial, we computed the root-mean-square-error (RMSE). The mean values of the resulting RMSE are listed in Table~\ref{tab:RMSE}. As apparent from the data, the proposed topology with one hidden layer ($l=1$) of width $w_1=7$ and the inputs $\boldsymbol{h}_q^\prime(\boldsymbol{x},\boldsymbol{u})$ performed best even though some ANN incorporated more parameters.

\begin{table}[h]
\caption{RMSE for different ReLU-ANN (where $w_i$ refers to $w_1,\dots,w_l$ and $\#_p$ reflects the number of parameters).}
\centering
\begin{tabular}{crrrr}
\toprule
\quad$\boldsymbol{\xi}$\quad\quad &\qquad$l$ &\qquad$w_i$ &\qquad$\#_p$ &\qquad RMSE \\
\midrule
$\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u})$ & $1$ & $5$ & $36$ & $0.4084$ \\[.5ex]
$\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u})$ & $1$ & $6$ & $43$ & $0.2589$ \\[.5ex]
$\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u})$ & $1$ & $7$ & $50$ & $0.1854$ \\[.5ex]
$\boldsymbol{h}^\prime_q(\boldsymbol{x},\boldsymbol{u})$ & $1$ & $8$ & $57$ & $0.1999$ \\[.5ex]
$(\,\boldsymbol{x}\,\,\,\boldsymbol{u}\,)^\top$ & $1$ & $12$ & $49$ & $0.2065$ \\[.5ex]
$(\,\boldsymbol{x}\,\,\,\boldsymbol{u}\,)^\top$ & $2$ & $5$ & $51$ & $0.3092$ \\[.5ex]
$(\,\boldsymbol{x}\,\,\,\boldsymbol{u}\,)^\top$ & $3$ & $4$ & $57$ &  $0.2735$\\
\bottomrule
\label{tab:RMSE}
\end{tabular}
\end{table}

\vspace{-5mm}

\subsection{Extension to two-dimensional case}\label{subsection:2D_example}

\begin{figure}[tp]
\centering
\includegraphics[trim={3cm 9cm 3cm 10cm},clip,scale=0.5]{fig2.pdf}
\caption{Illustration of the PWQ function $V_N$ (grey), the proposed ANN for the quadratic terms (blue), and the PWA difference $\Delta V_N$ (red) for the example in Section~\ref{subsection:2D_example}.}
\label{fig:PWQ_2D}
\end{figure}

We next show that solutions to Problem~\ref{prob:ANNforOVF} may also exist for $n>1$ and that they may be derived using strategies similar to those underlying our solution for $n=1$.
To this end, we consider the fictive function
\begin{equation}\label{eq:example_2D_PWQ}
V_N(\boldsymbol{x}) := \left\{
\begin{array}{ll}
\blind{2}\boldsymbol{x}_1^2+\boldsymbol{x}_2^2 & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(1)}, \\
2\boldsymbol{x}_1^2+\boldsymbol{x}_2^2 & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(2)}, \\
2\boldsymbol{x}_1^2+2\boldsymbol{x}_2^2 & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(3)}, \\
\blind{2}\boldsymbol{x}_1^2+2\boldsymbol{x}_2^2 & \text{if}\,\,\,\boldsymbol{x}\in\mathcal{R}^{(4)} \\
\end{array}
\right.
\end{equation}
(without specifying $N$) defined on the regions
\begin{align*}
    \mathcal{R}^{(1)}&:=\{\boldsymbol{x} \in \R^2 \,|\, \boldsymbol{x}_1 \geq 0,\, \boldsymbol{x}_2 \geq 0,\, \blind{+}\boldsymbol{x}_1+\boldsymbol{x}_2 \leq 1\}, \\
    \mathcal{R}^{(2)}&:=\{\boldsymbol{x} \in \R^2 \,|\, \boldsymbol{x}_1 \leq 0,\, \boldsymbol{x}_2 \geq 0,\, -\boldsymbol{x}_1+\boldsymbol{x}_2 \leq 1\}, \\
    \mathcal{R}^{(3)}&:=\{\boldsymbol{x} \in \R^2 \,|\, \boldsymbol{x}_1 \leq 0,\, \boldsymbol{x}_2 \leq 0,\, -\boldsymbol{x}_1-\boldsymbol{x}_2 \leq 1\}, \\
    \mathcal{R}^{(4)}&:=\{\boldsymbol{x} \in \R^2 \,|\, \boldsymbol{x}_1 \geq 0,\, \boldsymbol{x}_2 \leq 0,\, \blind{+}\boldsymbol{x}_1-\boldsymbol{x}_2 \leq 1\}.
\end{align*}
We next show that
\begin{align}
\nonumber
\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x}))=&- \max\{0 , \boldsymbol{x}_1 (-\boldsymbol{x}_1 +\boldsymbol{x}_2-1) \} \\
\nonumber
&- \max\{0 , \boldsymbol{x}_2 (-\boldsymbol{x}_1 -\boldsymbol{x}_2-1) \} \\
\nonumber
&- \max\{0 , \boldsymbol{x}_1 (-\boldsymbol{x}_1 -\boldsymbol{x}_2-1) \} \\
\nonumber
&- \max\{0 , \boldsymbol{x}_2 (\boldsymbol{x}_1 -\boldsymbol{x}_2-1) \} \\
\nonumber
&-0.5 \max\{0 , -\boldsymbol{x}_2 (\boldsymbol{x}_1 +\boldsymbol{x}_2-1) \} \\
\nonumber
&-0.5 \max\{0 , -\boldsymbol{x}_1 (\boldsymbol{x}_1 +\boldsymbol{x}_2-1) \} \\
\nonumber
&-0.5 \max\{0 , -\boldsymbol{x}_2 (-\boldsymbol{x}_1 +\boldsymbol{x}_2-1) \} \\
\label{eq:Phi_example_2D}
&-0.5 \max\{0 , -\boldsymbol{x}_1 (\boldsymbol{x}_1 -\boldsymbol{x}_2-1) \}
\end{align}
with $\boldsymbol{h}_v$ as in~\eqref{eq:hvStructure} represents a solution to Problem~\ref{prob:ANNforOVF}. In this context, we first note that $V_N(\boldsymbol{x})-\boldsymbol{\Phi}(\boldsymbol{h}_v(\boldsymbol{x}))$ is indeed PWA as visualized in Figure~\ref{fig:PWQ_2D}.
Furthermore, $\boldsymbol{\Phi}$ equals~\eqref{eq:ReLUoneLayer} with the parameters
\begin{equation}
\nonumber
\boldsymbol{W}^{(1)}\!=\begin{pmatrix}
-1 & \blind{+}0 & -1 & \blind{+}1 & \blind{+}0 \\
\blind{+}0 & -1 & \blind{+}0 & -1 & -1 \\
-1 & \blind{+}0 & -1 & -1 & \blind{+}0 \\
\blind{+}0 & -1 & \blind{+}0 & \blind{+}1 & -1 \\
\blind{+}0 & \blind{+}1 & \blind{+}0 & -1 & -1 \\
\blind{+}1 & \blind{+}0 & -1 & -1 & \blind{+}0 \\
\blind{+}0 & \blind{+}1 & \blind{+}0 & \blind{+}1 & -1 \\
\blind{+}1 & \blind{+}0 & -1 & \blind{+}1 & \blind{+}0 \\
\end{pmatrix},\,\,
\boldsymbol{W}^{(2)}\!=\begin{pmatrix}
-1 \\
-1 \\
-1 \\
-1 \\
-0.5 \\
-0.5 \\
-0.5 \\
-0.5 \\
\end{pmatrix}^{\!\top}\!\!\!,
\end{equation}
$\boldsymbol{a}^{(1)}=\boldsymbol{0}$, and $\boldsymbol{a}^{(2)}=0$ and the inputs $\boldsymbol{\xi}:=\boldsymbol{h}_v(\boldsymbol{x})$.
Hence, \eqref{eq:Phi_example_2D} is indeed a solution to Problem~\ref{prob:ANNforOVF}.

We briefly comment on the derivation of this solution. First, it is easy to see that every ReLU in~\eqref{eq:Phi_example_2D} is constructed in such a way that it is either active or inactive on the individual regions $\mathcal{R}^{(i)}$. For instance, $\max\{0 , \boldsymbol{x}_1 (-\boldsymbol{x}_1 +\boldsymbol{x}_2-1) \}$ is active on $\mathcal{R}^{(2)},\mathcal{R}^{(3)}$ and inactive on $\mathcal{R}^{(1)},\mathcal{R}^{(4)}$. In total, four ReLU are active on every region. Since we can freely choose the eight weighting factors of the ReLU, we can use these degrees of freedom to eliminate the eight quadratic terms in~\eqref{eq:example_2D_PWQ}. The strategy is closely related to the proof of Theorem~\ref{thm:sol1} and can, in principle, be generalized. However, formulating and solving the underlying system of equations is highly non-trivial.

\section{Conclusions and Outlook}
\label{sec:conclusion}

In this paper, we presented methods for exactly describing PWQ functions using tailored ANN with ReLU activations. In particular, we showed that the OVF in linear MPC can always be described by a ReLU-ANN with one hidden layer for the special case $n=1$ (see Thm.~\ref{thm:sol1} and Cor.~\ref{cor:ANNforV}). Moreover, according Theorem~\ref{thm:sol1ImpliesSol2}, a given description for the OVF can always be modified for exactly representing the associated Q-function (for any $n\geq1$).

We illustrated our results with various numerical examples. Two observations are of particular interest. First, the example in Section~\ref{subsection:example_learn_Q} indicates an advantage of the proposed ANN topologies for learning the Q-function. Second, the example in Section~\ref{subsection:2D_example} shows that the approach for representing the OVF might be extendable to $n>1$. Both observations offer interesting directions for further research.

redpajama_set_name: RedPajamaArXiv


text:
Live Customer Support 866.579.2262 Log In Log InJoin AAOAJoin
Home · Property Management · Real Estate Investing · Seizing on opportunities in Opportunity Zones
Seizing on opportunities in Opportunity Zones
Real estate attorney Roman Petra had a feeling that President Trump's affinity for property might translate into benefits for investors when his administration proposed sweeping tax reform legislation.
So when the Tax Cuts and Jobs Act of 2017 was signed into law, the Nelson Mullins Broad and Cassel attorney dug in.
Among the potential benefits to investors and real estate developers Petra found was a sometimes opaque opportunity in property tied to low-income U.S. Census tracts, which allowed investors to defer or even eliminate capital gains.
"Our practice is driven in part by helping clients seeking incentives and tax credits, including low-income housing tax credits, so we had some familiarity with the concept," says Petra.
"And we had a feeling that the tax law of 2017 might provide new programs for real estate, because of the president's real estate background," he adds.
In the months since they were first created in April 2018, the administration's Qualified Opportunity Zone designations have become the new darling of the commercial real estate industry, based on a theory that investors would be willing to put capital to work if they could defer or avoid writing a check for capital gains taxes.
Though many of the rules governing the zones remain murky, investors have flocked to capitalize on the potential for tax benefits that are similar to 1031 exchanges or previous iterations of low-income housing tax credits.
Today, it's not uncommon for major investment groups to tout $500 million or even $1 billion Opportunity Zone funds to develop — despite some noteworthy catches — property in the more than 8,700 such zones nationwide.
By some estimates, roughly $6 trillion — yes, with a "T" — worth of capital is being bundled in anticipation of being deployed in a fund targeting Opportunity Zone properties.
Florida, by comparison, has 427 such Opportunity Zones, some of which appear oddly designated and out of step with the goal of improving low-income areas.
In Sarasota, for instance, one Opportunity Zone touches the city's Bayfront. Another includes property on downtown's Main Street.
Tampa has Opportunity Zone land downtown as well, and in Ybor City and near the David A. Straz Jr. Center for the Performing Arts.
Similar zones are found along the Interstate 4 corridor between Tampa and Orlando, which has been a hotbed for logistics firms and distributors in recent years, and in Gibsonton.
Petra's client Thomas Ablum, founder of Chicago-based investment firm Ablum, Brown & Co. and a transplant to St. Petersburg, became intrigued after examining the tax implications with his accounting firm, Plante Moran, and seeing where many of the zones were located.
"Many of these zones are in deeply rural areas, areas that really are in need of redevelopment," Ablum says. "But many already have significant population, and that immediately peaked our interest."
So much so that Ablum and three partners last year formed the Capital Gains Opportunity Funds to invest $250 million in equity into Opportunity Zones before the end of 2020.
"A bad deal doesn't become good because it's in an Opportunity Zone. You still have to make good deals." — Thomas Ablum, Capital Gains Opportunity Fund
To date, Ablum and partners have focused on multifamily rental properties in places like Sacramento, Calif., and Norwalk, Conn.
"The asset classes we like are multifamily rental, student and senior housing, hospitality and mixed use," Ablum says. "We have good experience with each of those."
He's seeking local properties, as well.
"We're looking at a few properties in and around Tampa, a couple that are off the I-4 corridor," says Ablum, who previously co-headed corporate finance for New York securities and broker/dealer firm Rodman & Renshaw.
Unlike many Opportunity Zone funds, Capital Gains is matching investors' capital — about $15 million to $20 million per deal — to specific deals, rather than pooling it all into a general fund, as many have done.
Capital Gains also is vetting all of its deals through Plante Moran, too, to consider the tax impacts underlying the real estate investments.
It hasn't been an easy process, however.
Though new "guidance" in April from the U.S. Department of the Treasury clarified many misconceptions surrounding the zones, significant questions remain around what can be done, and when, and how property dispositions are to be handled.
Investors also are racing the clock. U.S. Internal Revenue Service rules say all Opportunity Zone investments must be placed by the end of this year to qualify for the ability to exclude 15% of the capital gain benefit when a property is sold at the end of 2026. (Investors can also place money in 2020, with lesser benefits.)
"The biggest issue I'm seeing is that many developers are waiting on the sidelines because all the requirements haven't been firmed up or they don't exist," Petra says. "But we're telling clients not to wait, just be mindful that you may have to be flexible going forward."
At the same time, sellers of property this year must wait until Dec. 31 to redeploy funds to defer capital gains, but then have a scant 180 days to identify an Opportunity Zone investment.
Maximum benefits from owning and improving property — another iron-clad IRS rule — that include the waiving of capital gains altogether come only after 10 years.
"The problem is, most real estate investors don't consider a 10-year investment window" says Ablum, who also worked for Prudential Bache Securities, Borg-Warner Acceptance Corp. and Walgreen Co.
"And that's because the (internal rate of return) tends to drop off precipitously after year seven. So we're spent a lot of time looking at scenarios in which the tax benefit pushes up the yield to make the deal more attractive overall.
"Ten years is a very long time — in real estate, it's a lifetime to some people. Because in 10 years, your luxury apartment building might not be considered luxury any longer."
Ablum also has faced hurdles regarding eventual dispositions.
"We spend about half our time pondering 'how are we going to get out of this?'" Ablum says. "You have to consider whether the area, not just your property, is growing or has the potential to grow over the next decade."
Additionally, he worries about macro-economic conditions.
"I've been through five recessions," he says. "A lot of people in real estate today haven't been through even one. I think there's a 100% chance that the U.S. will have some sort of economic recession sometime in the next 10 years."
Some properties just don't meet the criteria, either.
"We look at probably four to five new transactions a week, and half just don't fit," Ablum says.
And despite all the supposed money chasing Opportunity Zone investments, raising capital has been another obstacle.
"We have two of our partners who are full time working to raise money, and it hasn't been easy," he says. "I think that's because in the scheme of things, we're a small player. Our first commitment is going to be for about $30 million. And $250 million sounds like a lot, but it's not when considering these investments, and there's a lot of competition out there.
"Fortunately, we're ahead of the curve, we know the rules and we're working our model," Ablum says.
Meanwhile, Petra continues to grapple with the arcane differences between states as each has rolled out Opportunity Zone designations.
"There's not a universal system to work from," he says.
He thinks, too, that further rules could be forthcoming from the federal government.
But while the zones have altered the landscape for taxes, Ablum says some key real estate fundamentals still apply.
"A bad deal doesn't become good because it's in an Opportunity Zone," he says. "You still have to make good deals."
Source: businessobserverfl.com
Weighing Whether To...
With cryptocurrencies like bitcoin making news lately, you might be...
Smart Tips For Renting...
Posted on Jan 4, 2018 Particularly in proximity to business centers, condos...
5 Ways To Increase The...
When you hold property as a rental investment, it's only natural to...
How Airbnb Wants to Win...
MANHATTAN – As New York City landlords are upping the ante against...
Tax Implications for...
If you have outgrown your current residence or want to move for other...
5 Ways to Make Money in...
There are millions of people engaged in the real estate business with zero...
Three ways to add value...
A great investment in the property market doesn't always have to be...


text:
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DigitalPlatform.RFID
{
    public delegate void SerialPortEventHandler(Object sender, SerialPortEventArgs e);

    public class SerialPortEventArgs : EventArgs
    {
        public bool isOpend = false;
        public Byte[] receivedBytes = null;
    }

    public class ComModel
    {
        private SerialPort _sp = new SerialPort();

        public event SerialPortEventHandler comReceiveDataEvent = null;
        public event SerialPortEventHandler comOpenEvent = null;
        public event SerialPortEventHandler comCloseEvent = null;

        private Object thisLock = new Object();

        /// <summary>
        /// When serial received data, will call this method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataReceived(object sender, SerialDataReceivedEventArgs e)
        {

            if (_sp.BytesToRead <= 0)
            {
                return;
            }
            //Thread Safety explain in MSDN:
            // Any public static (Shared in Visual Basic) members of this type are thread safe.
            // Any instance members are not guaranteed to be thread safe.
            // So, we need to synchronize I/O
            lock (thisLock)
            {
                int len = _sp.BytesToRead;
                Byte[] data = new Byte[len];
                try
                {
                    _sp.Read(data, 0, len);
                }
                catch (System.Exception)
                {
                    //catch read exception
                }
                SerialPortEventArgs args = new SerialPortEventArgs();
                args.receivedBytes = data;
                if (comReceiveDataEvent != null)
                {
                    comReceiveDataEvent.Invoke(this, args);
                }
            }
        }

        /// <summary>
        /// Send bytes to device
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public bool Send(byte[] bytes, out string strError)
        {
            strError = "";
            if (!_sp.IsOpen)
            {
                strError = "_sp 尚未打开";
                return false;
            }

            try
            {
                _sp.Write(bytes, 0, bytes.Length);
            }
            catch (System.Exception ex)
            {
                strError = $"Write() 出现异常: {ex.Message}";
                return false;   //write failed
            }
            return true;        //write successfully
        }

        /// <summary>
        /// Open Serial port
        /// </summary>
        /// <param name="portName"></param>
        /// <param name="baudRate"></param>
        /// <param name="dataBits"></param>
        /// <param name="stopBits"></param>
        /// <param name="parity"></param>
        /// <param name="handshake"></param>
        public bool Open(string portName,
            String baudRate,
            string dataBits,
            string stopBits,
            string parity,
            string handshake,
            out string strError)
        {
            strError = "";

            if (_sp.IsOpen)
            {
                Close();
            }
            _sp.PortName = portName;
            _sp.BaudRate = Convert.ToInt32(baudRate);
            _sp.DataBits = Convert.ToInt16(dataBits);

            /**
             *  If the Handshake property is set to None the DTR and RTS pins
             *  are then freed up for the common use of Power, the PC on which
             *  this is being typed gives +10.99 volts on the DTR pin & +10.99
             *  volts again on the RTS pin if set to true. If set to false
             *  it gives -9.95 volts on the DTR, -9.94 volts on the RTS.
             *  These values are between +3 to +25 and -3 to -25 volts this
             *  give a dead zone to allow for noise immunity.
             *  http://www.codeproject.com/Articles/678025/Serial-Comms-in-Csharp-for-Beginners
             */
            if (handshake == "None")
            {
                //Never delete this property
                _sp.RtsEnable = true;
                _sp.DtrEnable = true;
            }

            SerialPortEventArgs args = new SerialPortEventArgs();
            try
            {
                _sp.StopBits = (StopBits)Enum.Parse(typeof(StopBits), stopBits);
                _sp.Parity = (Parity)Enum.Parse(typeof(Parity), parity);
                _sp.Handshake = (Handshake)Enum.Parse(typeof(Handshake), handshake);
                _sp.WriteTimeout = 2000; /*Write time out*/
                // _sp.ErrorReceived += _sp_ErrorReceived;
                // _sp.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
                _sp.Open();
                args.isOpend = true;
            }
            catch (System.Exception ex)
            {
                args.isOpend = false;
                strError = $"串口打开失败: {ex.Message}";
                return false;
            }

            if (comOpenEvent != null)
            {
                comOpenEvent.Invoke(this, args);
            }

            return true;
        }

        public SerialError SerialError { get; set; }

        private void _sp_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
        {
            this.SerialError = e.EventType;
        }

        /**
         *  Take care to avoid deadlock when calling Close on the SerialPort
         *  in response to a GUI event.
         *   An app involving the UI and the SerialPort freezes up when closing the SerialPort
         *   Deadlock can occur if Control.Invoke() is used in serial port event handlers
         *
         *  The typical scenario we encounter is occasional deadlock in an app
         *  that has a data received handler trying to update the GUI at the
         *  same time the GUI thread is trying to close the SerialPort (for
         *  example, in response to the user clicking a Close button).
         *
         *  The reason deadlock happens is that Close() waits for events to
         *  finish executing before it closes the port. You can address this
         *  problem in your apps in two ways:
         *
         *  (1)In your event handlers, replace every Control.Invoke call with
         *  Control.BeginInvoke, which executes asynchronously and avoids
         *  the deadlock condition. This is commonly used for deadlock avoidance
         *  when working with GUIs.
         *
         *  (2)Call serialPort.Close() on a separate thread. You may prefer this
         *  because this is less invasive than updating your Invoke calls.
         */
        /// <summary>
        /// Close serial port
        /// </summary>
        public void Close()
        {
            Thread closeThread = new Thread(new ThreadStart(CloseSpThread));
            closeThread.Start();
        }

        /// <summary>
        /// Close serial port thread
        /// </summary>
        private void CloseSpThread()
        {
            SerialPortEventArgs args = new SerialPortEventArgs();
            args.isOpend = false;
            try
            {
                _sp.Close(); //close the serial port
                             // _sp.DataReceived -= new SerialDataReceivedEventHandler(DataReceived);
            }
            catch (Exception)
            {
                args.isOpend = true;
            }
            if (comCloseEvent != null)
            {
                comCloseEvent.Invoke(this, args);
            }
        }
    }
}

redpajama_set_name: RedPajamaGithub


Any encoding which allows processing the first two lines in the way indicated above is allowed as source code encoding, this includes ASCII compatible encodings as well as certain multi-byte encodings such as Shift_JIS. It does not include encodings which use two or more bytes for all characters like e.g. UTF-16. The reason for this is to keep the encoding detection algorithm in the tokenizer simple.
Handling of escape sequences should continue to work as it does now, but with all possible source code encodings, that is standard string literals (both 8-bit and Unicode) are subject to escape sequence expansion while raw string literals only expand a very small subset of escape sequences.