本文目录一览:
- 1、MMsegmentation教程 6: 自定义运行设定
- 2、opencv常用函数
- 3、怎么用C语言做二维 三维 动画 窗口的程序?
- 4、1、假定某经济的消费函数为C=100+0.8Yd,Yd为可支配收入,投资支出为I=50,政府购买支出为G=200,政府转移
MMsegmentation教程 6: 自定义运行设定
我们已经支持 PyTorch 自带的所有优化器,唯一需要修改的地方是在配置文件里的 optimizer 域里面。
例如,如果您想使用 ADAM (注意如下操作可能会让模型表现下降),可以使用如下修改:
为了修改模型的学习率,使用者仅需要修改配置文件里 optimizer 的 lr 即可。
使用者可以参照 PyTorch 的 API 文档
直接设置参数。
一个自定义的优化器可以按照如下去定义:
假如您想增加一个叫做 MyOptimizer 的优化器,它的参数分别有 a , b , 和 c 。
您需要创建一个叫 mmseg/core/optimizer 的新文件夹。
然后再在文件,即 mmseg/core/optimizer/my_optimizer.py 里面去实现这个新优化器:
为了让上述定义的模块被框架发现,首先这个模块应该被导入到主命名空间 (main namespace) 里。
有两种方式可以实现它。
mmseg.core.optimizer.my_optimizer 模块将会在程序运行的开始被导入,并且 MyOptimizer 类将会自动注册。
需要注意只有包含 MyOptimizer 类的包 (package) 应当被导入。
而 mmseg.core.optimizer.my_optimizer.MyOptimizer 不能 被直接导入。
事实上,使用者完全可以用另一个按这样导入方法的文件夹结构,只要模块的根路径已经被添加到 PYTHONPATH 里面。
之后您可以在配置文件的 optimizer 域里面使用 MyOptimizer
在配置文件里,优化器被定义在 optimizer 域里,如下所示:
为了使用您自己的优化器,这个域可以被改成:
有些模型可能需要在优化器里有一些特别参数的设置,例如 批归一化层 (BatchNorm layers) 的 权重衰减 (weight decay)。
使用者可以通过自定义优化器的构造器去微调这些细粒度参数。
默认的优化器构造器的实现可以参照 这里 ,它也可以被用作新的优化器构造器的模板。
优化器没有实现的一些技巧应该通过优化器构造器 (optimizer constructor) 或者钩子 (hook) 去实现,如设置基于参数的学习率 (parameter-wise learning rates)。我们列出一些常见的设置,它们可以稳定或加速模型的训练。
如果您有更多的设置,欢迎在 PR 和 issue 里面提交。
我们根据默认的训练迭代步数 40k/80k 来设置学习率,这在 MMCV 里叫做 PolyLrUpdaterHook 。
我们也支持许多其他的学习率计划表: 这里 ,例如 CosineAnnealing 和 Poly 计划表。下面是一些例子:
工作流是一个专门定义运行顺序和轮数 (running order and epochs) 的列表 (phase, epochs)。
默认情况下它设置成:
意思是训练是跑 1 个 epoch。有时候使用者可能想检查模型在验证集上的一些指标(如 损失 loss,精确性 accuracy),我们可以这样设置工作流:
于是 1 个 epoch 训练,1 个 epoch 验证将交替运行。
注意 :
如果钩子已经在 MMCV 里被实现,如下所示,您可以直接修改配置文件来使用钩子:
以下的常用的钩子没有被 custom_hooks 注册:
在这些钩子里,只有 logger hook 有 VERY_LOW 优先级,其他的优先级都是 NORMAL 。
上述提及的教程已经包括了如何修改 optimizer_config , momentum_config 和 lr_config 。
这里我们展示我们如何处理 log_config , checkpoint_config 和 evaluation 。
MMCV runner 将使用 checkpoint_config 去初始化 CheckpointHook .
使用者可以设置 max_keep_ckpts 来仅保存一小部分检查点或者通过 save_optimizer 来决定是否保存优化器的状态字典 (state dict of optimizer)。 更多使用参数的细节请参考 这里 。
log_config 包裹了许多日志钩 (logger hooks) 而且能去设置间隔 (intervals)。现在 MMCV 支持 WandbLoggerHook , MlflowLoggerHook 和 TensorboardLoggerHook 。
详细的使用请参照 文档 。
evaluation 的配置文件将被用来初始化 EvalHook 。
除了 interval 键,其他的像 metric 这样的参数将被传递给 dataset.evaluate() 。
opencv常用函数
原文链接:
1、cvLoadImage:将图像文件加载至内存;
2、cvNamedWindow:在屏幕上创建一个窗口;
3、cvShowImage:在一个已创建好的窗口中显示图像;
4、cvWaitKey:使程序暂停,等待用户触发一个按键操作;
5、cvReleaseImage:释放图像文件所分配的内存;
6、cvDestroyWindow:销毁显示图像文件的窗口;
7、cvCreateFileCapture:通过参数设置确定要读入的AVI文件;
8、cvQueryFrame:用来将下一帧视频文件载入内存;
9、cvReleaseCapture:释放CvCapture结构开辟的内存空间;
10、cvCreateTrackbar:创建一个滚动条;
11、cvSetCaptureProperty:设置CvCapture对象的各种属性;
12、cvGetCaptureProperty:查询CvCapture对象的各种属性;
13、cvGetSize:当前图像结构的大小;
14、cvSmooth:对图像进行平滑处理;
15、cvPyrDown:图像金字塔,降采样,图像缩小为原来四分之一;
16、cvCanny:Canny边缘检测;
17、cvCreateCameraCapture:从摄像设备中读入数据;
18、cvCreateVideoWriter:创建一个写入设备以便逐帧将视频流写入视频文件;
19、cvWriteFrame:逐帧将视频流写入文件;
20、cvReleaseVideoWriter:释放CvVideoWriter结构开辟的内存空间;
21、CV_MAT_ELEM:从矩阵中得到一个元素;
22、cvAbs:计算数组中所有元素的绝对值;
23、cvAbsDiff:计算两个数组差值的绝对值;
24、cvAbsDiffS:计算数组和标量差值的绝对值;
25、cvAdd:两个数组的元素级的加运算;
26、cvAddS:一个数组和一个标量的元素级的相加运算;
27、cvAddWeighted:两个数组的元素级的加权相加运算(alpha运算);
28、cvAvg:计算数组中所有元素的平均值;
29、cvAvgSdv:计算数组中所有元素的绝对值和标准差;
30、cvCalcCovarMatrix:计算一组n维空间向量的协方差;
31、cvCmp:对两个数组中的所有元素运用设置的比较操作;
32、cvCmpS:对数组和标量运用设置的比较操作;
33、cvConvertScale:用可选的缩放值转换数组元素类型;
34、cvCopy:把数组中的值复制到另一个数组中;
35、cvCountNonZero:计算数组中非0值的个数;
36、cvCrossProduct:计算两个三维向量的向量积(叉积);
37、cvCvtColor:将数组的通道从一个颜色空间转换另外一个颜色空间;
38、cvDet:计算方阵的行列式;
39、cvDiv:用另外一个数组对一个数组进行元素级的除法运算;
40、cvDotProduct:计算两个向量的点积;
41、cvEigenVV:计算方阵的特征值和特征向量;
42、cvFlip:围绕选定轴翻转;
43、cvGEMM:矩阵乘法;
44、cvGetCol:从一个数组的列中复制元素;
45、cvGetCols:从数据的相邻的多列中复制元素;
46、cvGetDiag:复制数组中对角线上的所有元素;
47、cvGetDims:返回数组的维数;
48、cvGetDimSize:返回一个数组的所有维的大小;
49、cvGetRow:从一个数组的行中复制元素值;
50、cvGetRows:从一个数组的多个相邻的行中复制元素值;
51、cvGetSize:得到二维的数组的尺寸,以CvSize返回;
52、cvGetSubRect:从一个数组的子区域复制元素值;
53、cvInRange:检查一个数组的元素是否在另外两个数组中的值的范围内;
54、cvInRangeS:检查一个数组的元素的值是否在另外两个标量的范围内;
55、cvInvert:求矩阵的逆;
56、cvMahalonobis:计算两个向量间的马氏距离;
57、cvMax:在两个数组中进行元素级的取最大值操作;
58、cvMaxS:在一个数组和一个标量中进行元素级的取最大值操作;
59、cvMerge:把几个单通道图像合并为一个多通道图像;
60、cvMin:在两个数组中进行元素级的取最小值操作;
61、cvMinS:在一个数组和一个标量中进行元素级的取最小值操作;
62、cvMinMaxLoc:寻找数组中的最大最小值;
63、cvMul:计算两个数组的元素级的乘积(点乘);
64、cvNot:按位对数组中的每一个元素求反;
65、cvNormalize:将数组中元素进行归一化;
66、cvOr:对两个数组进行按位或操作;
67、cvOrs:在数组与标量之间进行按位或操作;
68、cvReduce:通过给定的操作符将二维数组简为向量;
69、cvRepeat:以平铺的方式进行数组复制;
70、cvSet:用给定值初始化数组;
71、cvSetZero:将数组中所有元素初始化为0;
72、cvSetIdentity:将数组中对角线上的元素设为1,其他置0;
73、cvSolve:求出线性方程组的解;
74、cvSplit:将多通道数组分割成多个单通道数组;
75、cvSub:两个数组元素级的相减;
76、cvSubS:元素级的从数组中减去标量;
77、cvSubRS:元素级的从标量中减去数组;
78、cvSum:对数组中的所有元素求和;
79、cvSVD:二维矩阵的奇异值分解;
80、cvSVBkSb:奇异值回代计算;
81、cvTrace:计算矩阵迹;
82、cvTranspose:矩阵的转置运算;
83、cvXor:对两个数组进行按位异或操作;
84、cvXorS:在数组和标量之间进行按位异或操作;
85、cvZero:将所有数组中的元素置为0;
86、cvConvertScaleAbs:计算可选的缩放值的绝对值之后再转换数组元素的类型;
87、cvNorm:计算数组的绝对范数, 绝对差分范数或者相对差分范数;
88、cvAnd:对两个数组进行按位与操作;
89、cvAndS:在数组和标量之间进行按位与操作;
90、cvScale:是cvConvertScale的一个宏,可以用来重新调整数组的内容,并且可以将参数从一种数据类型转换为另一种;
91、cvT:是函数cvTranspose的缩写;
92、cvLine:画直线;
93、cvRectangle:画矩形;
94、cvCircle:画圆;
95、cvEllipse:画椭圆;
96、cvEllipseBox:使用外接矩形描述椭圆;
97、cvFillPoly、cvFillConvexPoly、cvPolyLine:画多边形;
98、cvPutText:在图像上输出一些文本;
99、cvInitFont:采用一组参数配置一些用于屏幕输出的基本个特定字体;
100、cvSave:矩阵保存;
101、cvLoad:矩阵读取;
102、cvOpenFileStorage:为读/写打开存储文件;
103、cvReleaseFileStorage:释放存储的数据;
104、cvStartWriteStruct:开始写入新的数据结构;
105、cvEndWriteStruct:结束写入数据结构;
106、cvWriteInt:写入整数型;
107、cvWriteReal:写入浮点型;
108、cvWriteString:写入字符型;
109、cvWriteComment:写一个XML或YAML的注释字串;
110、cvWrite:写一个对象;
111、cvWriteRawData:写入多个数值;
112、cvWriteFileNode:将文件节点写入另一个文件存储器;
113、cvGetRootFileNode:获取存储器最顶层的节点;
114、cvGetFileNodeByName:在映图或存储器中找到相应节点;
115、cvGetHashedKey:为名称返回一个惟一的指针;
116、cvGetFileNode:在映图或文件存储器中找到节点;
117、cvGetFileNodeName:返回文件的节点名;
118、cvReadInt:读取一个无名称的整数型;
119、cvReadIntByName:读取一个有名称的整数型;
120、cvReadReal:读取一个无名称的浮点型;
121、cvReadRealByName:读取一个有名称的浮点型;
122、cvReadString:从文件节点中寻找字符串;
123、cvReadStringByName:找到一个有名称的文件节点并返回它;
124、cvRead:将对象解码并返回它的指针;
125、cvReadByName:找到对象并解码;
126、cvReadRawData:读取多个数值;
127、cvStartReadRawData:初始化文件节点序列的读取;
128、cvReadRawDataSlice:读取文件节点的内容;
129、cvGetModuleInfo:检查IPP库是否已经正常安装并且检验运行是否正常;
130、cvResizeWindow:用来调整窗口的大小;
131、cvSaveImage:保存图像;
132、cvMoveWindow:将窗口移动到其左上角为x,y的位置;
133、cvDestroyAllWindow:用来关闭所有窗口并释放窗口相关的内存空间;
134、cvGetTrackbarPos:读取滑动条的值;
135、cvSetTrackbarPos:设置滑动条的值;
136、cvGrabFrame:用于快速将视频帧读入内存;
137、cvRetrieveFrame:对读入帧做所有必须的处理;
138、cvConvertImage:用于在常用的不同图像格式之间转换;
139、cvErode:形态腐蚀;
140、cvDilate:形态学膨胀;
141、cvMorphologyEx:更通用的形态学函数;
142、cvFloodFill:漫水填充算法,用来进一步控制哪些区域将被填充颜色;
143、cvResize:放大或缩小图像;
144、cvPyrUp:图像金字塔,将现有的图像在每个维度上都放大两倍;
145、cvPyrSegmentation:利用金字塔实现图像分割;
146、cvThreshold:图像阈值化;
147、cvAcc:可以将8位整数类型图像累加为浮点图像;
148、cvAdaptiveThreshold:图像自适应阈值;
149、cvFilter2D:图像卷积;
150、cvCopyMakeBorder:将特定的图像轻微变大,然后以各种方式自动填充图像边界;
151、cvSobel:图像边缘检测,Sobel算子;
152、cvLaplace:拉普拉斯变换、图像边缘检测;
153、cvHoughLines2:霍夫直线变换;
154、cvHoughCircles:霍夫圆变换;
155、cvRemap:图像重映射,校正标定图像,图像插值;
156、cvWarpAffine:稠密仿射变换;
157、cvGetQuadrangleSubPix:仿射变换;
158、cvGetAffineTransform:仿射映射矩阵的计算;
159、cvCloneImage:将整个IplImage结构复制到新的IplImage中;
160、cv2DRotationMatrix:仿射映射矩阵的计算;
161、cvTransform:稀疏仿射变换;
162、cvWarpPerspective:密集透视变换(单应性);
163、cvGetPerspectiveTransform:计算透视映射矩阵;
164、cvPerspectiveTransform:稀疏透视变换;
165、cvCartToPolar:将数值从笛卡尔空间到极坐标(极性空间)进行映射;
166、cvPolarToCart:将数值从极性空间到笛卡尔空间进行映射;
167、cvLogPolar:对数极坐标变换;
168、cvDFT:离散傅里叶变换;
169、cvMulSpectrums:频谱乘法;
170、cvDCT:离散余弦变换;
171、cvIntegral:计算积分图像;
172、cvDistTransform:图像的距离变换;
173、cvEqualizeHist:直方图均衡化;
174、cvCreateHist:创建一新直方图;
175、cvMakeHistHeaderForArray:根据已给出的数据创建直方图;
176、cvNormalizeHist:归一化直方图;
177、cvThreshHist:直方图阈值函数;
178、cvCalcHist:从图像中自动计算直方图;
179、cvCompareHist:用于对比两个直方图的相似度;
180、cvCalcEMD2:陆地移动距离(EMD)算法;
181、cvCalcBackProject:反向投影;
182、cvCalcBackProjectPatch:图块的方向投影;
183、cvMatchTemplate:模板匹配;
184、cvCreateMemStorage:用于创建一个内存存储器;
185、cvCreateSeq:创建序列;
186、cvSeqInvert:将序列进行逆序操作;
187、cvCvtSeqToArray:复制序列的全部或部分到一个连续内存数组中;
188、cvFindContours:从二值图像中寻找轮廓;
189、cvDrawContours:绘制轮廓;
190、cvApproxPoly:使用多边形逼近一个轮廓;
191、cvContourPerimeter:轮廓长度;
192、cvContoursMoments:计算轮廓矩;
193、cvMoments:计算Hu不变矩;
194、cvMatchShapes:使用矩进行匹配;
195、cvInitLineIterator:对任意直线上的像素进行采样;
196、cvSampleLine:对直线采样;
197、cvAbsDiff:帧差;
198、cvWatershed:分水岭算法;
199、cvInpaint:修补图像;
200、cvGoodFeaturesToTrack:寻找角点;
201、cvFindCornerSubPix:用于发现亚像素精度的角点位置;
202、cvCalcOpticalFlowLK:实现非金字塔的Lucas-Kanade稠密光流算法;
203、cvMeanShift:mean-shift跟踪算法;
204、cvCamShift:camshift跟踪算法;
205、cvCreateKalman:创建Kalman滤波器;
206、cvCreateConDensation:创建condensation滤波器;
207、cvConvertPointsHomogenious:对齐次坐标进行转换;
208、cvFindChessboardCorners:定位棋盘角点;
209、cvFindHomography:计算单应性矩阵;
210、cvRodrigues2:罗德里格斯变换;
211、cvFitLine:直线拟合算法;
212、cvCalcCovarMatrix:计算协方差矩阵;
213、cvInvert:计算协方差矩阵的逆矩阵;
214、cvMahalanobis:计算Mahalanobis距离;
215、cvKMeans2:K均值;
216、cvCloneMat:根据一个已有的矩阵创建一个新矩阵;
217、cvPreCornerDetect:计算用于角点检测的特征图;
218、cvGetImage:CvMat图像数据格式转换成IplImage图像数据格式;
219、cvMatMul:两矩阵相乘;
怎么用C语言做二维 三维 动画 窗口的程序?
我有相关的资料(原版英文书), 但无法传递给你!!! 给你个实例程序:(太长,程序没发完)
/*
GRAPHICS DEMO FOR TURBO C 2.0
Copyright (c) 1987,88 Borland International. All rights reserved.
From the command line, use:
tcc bgidemo graphics.lib
*/
#ifdef __TINY__
#error BGIDEMO will not run in the tiny model.
#endif
#include dos.h
#include math.h
#include conio.h
#include stdio.h
#include stdlib.h
#include stdarg.h
#include graphics.h
#define ESC 0x1b /* Define the escape key */
#define TRUE 1 /* Define some handy constants */
#define FALSE 0 /* Define some handy constants */
#define PI 3.14159 /* Define a value for PI */
#define ON 1 /* Define some handy constants */
#define OFF 0 /* Define some handy constants */
char *Fonts[] = {
"DefaultFont", "TriplexFont", "SmallFont",
"SansSerifFont", "GothicFont"
};
char *LineStyles[] = {
"SolidLn", "DottedLn", "CenterLn", "DashedLn", "UserBitLn"
};
char *FillStyles[] = {
"EmptyFill", "SolidFill", "LineFill", "LtSlashFill",
"SlashFill", "BkSlashFill", "LtBkSlashFill", "HatchFill",
"XHatchFill", "InterleaveFill", "WideDotFill", "CloseDotFill"
};
char *TextDirect[] = {
"HorizDir", "VertDir"
};
char *HorizJust[] = {
"LeftText", "CenterText", "RightText"
};
char *VertJust[] = {
"BottomText", "CenterText", "TopText"
};
struct PTS {
int x, y;
}; /* Structure to hold vertex points */
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
double AspectRatio; /* Aspect ratio of a pixel on the screen*/
int MaxX, MaxY; /* The maximum resolution of the screen */
int MaxColors; /* The maximum # of colors available */
int ErrorCode; /* Reports any graphics errors */
struct palettetype palette; /* Used to read palette info */
/* */
/* Function prototypes */
/* */
void Initialize(void);
void ReportStatus(void);
void TextDump(void);
void Bar3DDemo(void);
void RandomBars(void);
void TextDemo(void);
void ColorDemo(void);
void ArcDemo(void);
void CircleDemo(void);
void PieDemo(void);
void BarDemo(void);
void LineRelDemo(void);
void PutPixelDemo(void);
void PutImageDemo(void);
void LineToDemo(void);
void LineStyleDemo(void);
void CRTModeDemo(void);
void UserLineStyleDemo(void);
void FillStyleDemo(void);
void FillPatternDemo(void);
void PaletteDemo(void);
void PolyDemo(void);
void SayGoodbye(void);
void Pause(void);
void MainWindow(char *header);
void StatusLine(char *msg);
void DrawBorder(void);
void changetextstyle(int font, int direction, int charsize);
int gprintf(int *xloc, int *yloc, char *fmt, ... );
/* */
/* Begin main function */
/* */
int main()
{
Initialize(); /* Set system into Graphics mode */
ReportStatus(); /* Report results of the initialization */
ColorDemo(); /* Begin actual demonstration */
if( GraphDriver==EGA || GraphDriver==EGALO || GraphDriver==VGA )
PaletteDemo();
PutPixelDemo();
PutImageDemo();
Bar3DDemo();
BarDemo();
RandomBars();
ArcDemo();
CircleDemo();
PieDemo();
LineRelDemo();
LineToDemo();
LineStyleDemo();
UserLineStyleDemo();
TextDump();
TextDemo();
CRTModeDemo();
FillStyleDemo();
FillPatternDemo();
PolyDemo();
SayGoodbye(); /* Give user the closing screen */
closegraph(); /* Return the system to text mode */
return(0);
}
/* */
/* INITIALIZE: Initializes the graphics system and reports */
/* any errors which occured. */
/* */
void Initialize(void)
{
int xasp, yasp; /* Used to read the aspect ratio*/
GraphDriver = DETECT; /* Request auto-detection */
initgraph( GraphDriver, GraphMode, "" );
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode != grOk ){ /* Error occured during init */
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
exit( 1 );
}
getpalette( palette ); /* Read the palette from board */
MaxColors = getmaxcolor() + 1; /* Read maximum number of colors*/
MaxX = getmaxx();
MaxY = getmaxy(); /* Read size of screen */
getaspectratio( xasp, yasp ); /* read the hardware aspect */
AspectRatio = (double)xasp / (double)yasp; /* Get correction factor */
}
/* */
/* REPORTSTATUS: Report the current configuration of the system */
/* after the auto-detect initialization. */
/* */
void ReportStatus(void)
{
struct viewporttype viewinfo; /* Params for inquiry procedures*/
struct linesettingstype lineinfo;
struct fillsettingstype fillinfo;
struct textsettingstype textinfo;
struct palettetype palette;
char *driver, *mode; /* Strings for driver and mode */
int x, y;
getviewsettings( viewinfo );
getlinesettings( lineinfo );
getfillsettings( fillinfo );
gettextsettings( textinfo );
getpalette( palette );
x = 10;
y = 4;
MainWindow( "Status report after InitGraph" );
settextjustify( LEFT_TEXT, TOP_TEXT );
driver = getdrivername();
mode = getmodename(GraphMode); /* get current setting */
gprintf( x, y, "Graphics device : %-20s (%d)", driver, GraphDriver );
gprintf( x, y, "Graphics mode : %-20s (%d)", mode, GraphMode );
gprintf( x, y, "Screen resolution : ( 0, 0, %d, %d )", getmaxx(), getmaxy() );
gprintf( x, y, "Current view port : ( %d, %d, %d, %d )",
viewinfo.left, viewinfo.top, viewinfo.right, viewinfo.bottom );
gprintf( x, y, "Clipping : %s", viewinfo.clip ? "ON" : "OFF" );
gprintf( x, y, "Current position : ( %d, %d )", getx(), gety() );
gprintf( x, y, "Colors available : %d", MaxColors );
gprintf( x, y, "Current color : %d", getcolor() );
gprintf( x, y, "Line style : %s", LineStyles[ lineinfo.linestyle ] );
gprintf( x, y, "Line thickness : %d", lineinfo.thickness );
gprintf( x, y, "Current fill style : %s", FillStyles[ fillinfo.pattern ] );
gprintf( x, y, "Current fill color : %d", fillinfo.color );
gprintf( x, y, "Current font : %s", Fonts[ textinfo.font ] );
gprintf( x, y, "Text direction : %s", TextDirect[ textinfo.direction ] );
gprintf( x, y, "Character size : %d", textinfo.charsize );
gprintf( x, y, "Horizontal justify : %s", HorizJust[ textinfo.horiz ] );
gprintf( x, y, "Vertical justify : %s", VertJust[ textinfo.vert ] );
Pause(); /* Pause for user to read screen*/
}
/* */
/* TEXTDUMP: Display the all the characters in each of the */
/* available fonts. */
/* */
void TextDump()
{
static int CGASizes[] = {
1, 3, 7, 3, 3 };
static int NormSizes[] = {
1, 4, 7, 4, 4 };
char buffer[80];
int font, ch, wwidth, lwidth, size;
struct viewporttype vp;
for( font=0 ; font5 ; ++font ){ /* For each available font */
sprintf( buffer, "%s Character Set", Fonts[font] );
MainWindow( buffer ); /* Display fontname as banner */
getviewsettings( vp ); /* read current viewport */
settextjustify( LEFT_TEXT, TOP_TEXT );
moveto( 2, 3 );
buffer[1] = '\0'; /* Terminate string */
wwidth = vp.right - vp.left; /* Determine the window width */
lwidth = textwidth( "H" ); /* Get average letter width */
if( font == DEFAULT_FONT ){
changetextstyle( font, HORIZ_DIR, 1 );
ch = 0;
while( ch 256 ){ /* For each possible character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (getx() + lwidth) wwidth )
moveto( 2, gety() + textheight("H") + 3 );
++ch; /* Goto the next character */
}
}
else{
size = (MaxY 200) ? CGASizes[font] : NormSizes[font];
changetextstyle( font, HORIZ_DIR, size );
ch = '!'; /* Begin at 1st printable */
while( ch 127 ){ /* For each printable character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (lwidth+getx()) wwidth ) /* Are we still in window? */
moveto( 2, gety()+textheight("H")+3 );
++ch; /* Goto the next character */
}
}
Pause(); /* Pause until user acks */
} /* End of FONT loop */
}
/* */
/* BAR3DDEMO: Display a 3-D bar chart on the screen. */
/* */
void Bar3DDemo(void)
{
static int barheight[] = {
1, 3, 5, 4, 3, 2, 1, 5, 4, 2, 3 };
struct viewporttype vp;
int xstep, ystep;
int i, j, h, color, bheight;
char buffer[10];
MainWindow( "Bar 3-D / Rectangle Demonstration" );
h = 3 * textheight( "H" );
getviewsettings( vp );
settextjustify( CENTER_TEXT, TOP_TEXT );
changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
outtextxy( MaxX/2, 6, "These are 3-D Bars" );
changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
setviewport( vp.left+50, vp.top+40, vp.right-50, vp.bottom-10, 1 );
getviewsettings( vp );
line( h, h, h, vp.bottom-vp.top-h );
line( h, (vp.bottom-vp.top)-h, (vp.right-vp.left)-h, (vp.bottom-vp.top)-h );
xstep = ((vp.right-vp.left) - (2*h)) / 10;
ystep = ((vp.bottom-vp.top) - (2*h)) / 5;
j = (vp.bottom-vp.top) - h;
settextjustify( CENTER_TEXT, CENTER_TEXT );
for( i=0 ; i6 ; ++i ){
line( h/2, j, h, j );
itoa( i, buffer, 10 );
outtextxy( 0, j, buffer );
j -= ystep;
}
j = h;
settextjustify( CENTER_TEXT, TOP_TEXT );
for( i=0 ; i11 ; ++i ){
color = random( MaxColors );
setfillstyle( i+1, color );
line( j, (vp.bottom-vp.top)-h, j, (vp.bottom-vp.top-3)-(h/2) );
itoa( i, buffer, 10 );
outtextxy( j, (vp.bottom-vp.top)-(h/2), buffer );
if( i != 10 ){
bheight = (vp.bottom-vp.top) - h - 1;
bar3d( j, (vp.bottom-vp.top-h)-(barheight[i]*ystep), j+xstep, bheight, 15, 1 );
}
j += xstep;
}
Pause(); /* Pause for user's response */
}
/* */
/* RANDOMBARS: Display random bars */
/* */
void RandomBars(void)
{
int color;
MainWindow( "Random Bars" );
StatusLine( "Esc aborts or press a key..." ); /* Put msg at bottom of screen */
while( !kbhit() ){ /* Until user enters a key... */
color = random( MaxColors-1 )+1;
setcolor( color );
setfillstyle( random(11)+1, color );
bar3d( random( getmaxx() ), random( getmaxy() ),
random( getmaxx() ), random( getmaxy() ), 0, OFF);
}
Pause(); /* Pause for user's response */
}
/* */
/* TEXTDEMO: Show each font in several sizes to the user. */
/* */
void TextDemo(void)
{
int charsize[] = {
1, 3, 7, 3, 4 };
int font, size;
int h, x, y, i;
struct viewporttype vp;
char buffer[80];
for( font=0 ; font5 ; ++font ){ /* For each of the four fonts */
sprintf( buffer, "%s Demonstration", Fonts[font] );
MainWindow( buffer );
getviewsettings( vp );
changetextstyle( font, VERT_DIR, charsize[font] );
settextjustify( CENTER_TEXT, BOTTOM_TEXT );
outtextxy( 2*textwidth("M"), vp.bottom - 2*textheight("M"), "Vertical" );
changetextstyle( font, HORIZ_DIR, charsize[font] );
settextjustify( LEFT_TEXT, TOP_TEXT );
outtextxy( 2*textwidth("M"), 2, "Horizontal" );
settextjustify( CENTER_TEXT, CENTER_TEXT );
x = (vp.right - vp.left) / 2;
y = textheight( "H" );
for( i=1 ; i5 ; ++i ){ /* For each of the sizes */
size = (font == SMALL_FONT) ? i+3 : i;
changetextstyle( font, HORIZ_DIR, size );
h = textheight( "H" );
y += h;
sprintf( buffer, "Size %d", size );
outtextxy( x, y, buffer );
}
if( font != DEFAULT_FONT ){ /* Show user declared font size */
y += h / 2; /* Move down the screen */
settextjustify( CENTER_TEXT, TOP_TEXT );
setusercharsize( 5, 6, 3, 2 );
changetextstyle( font, HORIZ_DIR, USER_CHAR_SIZE );
outtextxy( (vp.right-vp.left)/2, y, "User Defined Size" );
}
Pause(); /* Pause to let user look */
} /* End of FONT loop */
}
/* */
/* COLORDEMO: Display the current color palette on the screen. */
/* */
void ColorDemo(void)
{
struct viewporttype vp;
int color, height, width;
int x, y, i, j;
char cnum[5];
MainWindow( "Color Demonstration" ); /* Show demonstration name */
color = 1;
getviewsettings( vp ); /* Get the current window size */
width = 2 * ( (vp.right+1) / 16 ); /* Get box dimensions */
height = 2 * ( (vp.bottom-10) / 10 );
x = width / 2;
y = height / 2; /* Leave 1/2 box border */
for( j=0 ; j3 ; ++j ){ /* Row loop */
for( i=0 ; i5 ; ++i ){ /* Column loop */
setfillstyle(SOLID_FILL, color); /* Set to solid fill in color */
setcolor( color ); /* Set the same border color */
bar( x, y, x+width, y+height ); /* Draw the rectangle */
rectangle( x, y, x+width, y+height ); /* outline the rectangle */
if( color == BLACK ){ /* If box was black... */
setcolor( WHITE ); /* Set drawing color to white */
rectangle( x, y, x+width, y+height ); /* Outline black in white*/
}
itoa( color, cnum, 10 ); /* Convert # to ASCII */
outtextxy( x+(width/2), y+height+4, cnum ); /* Show color # */
color = ++color % MaxColors; /* Advance to the next color */
x += (width / 2) * 3; /* move the column base */
} /* End of Column loop */
y += (height / 2) * 3; /* move the row base */
x = width / 2; /* reset column base */
} /* End of Row loop */
Pause(); /* Pause for user's response */
}
/* */
/* ARCDEMO: Display a random pattern of arcs on the screen */
/* until the user says enough. */
/* */
void ArcDemo(void)
{
int mradius; /* Maximum radius allowed */
int eangle; /* Random end angle of Arc */
struct arccoordstype ai; /* Used to read Arc Cord info */
MainWindow( "Arc Demonstration" );
StatusLine( "ESC Aborts - Press a Key to stop" );
mradius = MaxY / 10; /* Determine the maximum radius */
while( !kbhit() ){ /* Repeat until a key is hit */
setcolor( random( MaxColors - 1 ) + 1 ); /* Randomly select a color */
eangle = random( 358 ) + 1; /* Select an end angle */
arc( random(MaxX), random(MaxY), random(eangle), eangle, mradius );
getarccoords( ai ); /* Read Cord data */
line( ai.x, ai.y, ai.xstart, ai.ystart ); /* line from start to center */
line( ai.x, ai.y, ai.xend, ai.yend ); /* line from end to center */
} /* End of WHILE not KBHIT */
Pause(); /* Wait for user's response */
}
1、假定某经济的消费函数为C=100+0.8Yd,Yd为可支配收入,投资支出为I=50,政府购买支出为G=200,政府转移
①增加政府购买;
②减少税收;
③增加政府购买和税收同一数额(以便预算平衡)实现充分就业,各需多少可支配收入?
1)均衡收入_=100+0.8(Y-250+62.5)+50+200,_獾_=1000
2)投资乘数=dY/di=1/(1-0.8)=5
政府支出乘数:=dY/dg=1/(1-0.8)=5
税收乘数=dY/dt=-0.8/(1-0.8)=-4
转移支付乘数=dY/dTr=0.8/(1-0.8)=4
平衡预算乘数=政府支出乘数+税收乘数=1
3)IS曲线:由Y=40+0.8(Y-50)+140-10r+50_简得到r=19-0.01Y
LM曲线:由0.5Y-5r=100_简得到r=0.1Y-20
4)均衡的国民收入、利率、投资各位多少?
联立上面两个方程解得
均衡的国民收入=325,
利率=12.5
投资=140-10r=15
拓展资料:
(1)Yd=Y-T+TR=Y-0.25Y+62.5=0.75Y+62.5
Y=C+I+G=100+0.8(0.75Y+62.5)+50+200=0.6Y+400
Y=1000
(2)投资乘数:ki
政府支出乘数:kg
税收乘数:kT
转移支付乘数:Ktr
平衡预算乘数:kB=kg+kT=1
(3)①用增加政府购买的方法:
△Y=△G×kg=△G×2.5=1200-1000=200
需增加支出:
②用减少税收的方法:
△Y=△T×kT=△T×(-1.5)=200
需减少税收
③用预算平均的方法:
△Y=△G(或△T×kB=△G(或△T)×1=200
△G(或△T)=200
需增加政府购买和税收各200亿美元才预算达到平衡的基础上实现充分就业。可支配收入为Yd=Y-T+TR=Y-250+62.5=Y-187.5由收入恒等式得Y=C+I+G=100+0.8(Y-187.5)+50+200,所以均衡国民收入Y=1000,根据消费函数可知边际消费倾向MPC=0.8,则投资乘数K1=1/1-MPC=5;政府购买乘数Kg=1/1-6=5;税收乘数Kt=-MPC/(1-MPC)=-4转移支付乘数Ktr=B./(1-B.)=4;平衡预算乘数KB.=1-MPC/(1-MPC)=1,均衡收入_=100+0.8(Y-250+62.5)+50+200,_獾_=1000,投资乘数=dY/di=1/(1-0.8)=5。政府支出乘数:=dY/dg=1/(1-0.8)=5,税收乘数=dY/dt=-0.8/(1-0.8)=-4,转移支付乘数=dY/dTr=0.8/(1-0.8)=4,平衡预算乘数=政府支出乘数+税收乘数。